Page 1 of 1

Memory leak when using RAW, Filter and I2S.

Posted: Thu Mar 05, 2020 8:46 am
by Ismael
Good morning.

Starting from the VoIP example, I tried to communicate 2 devices using UDP using 2 ESP32 LyraT v4.3 boards.
All the scenario works well (despite of some noise in the channel, but this could be another topic that I would like to analyze first).
Due to the limited memory of RAM that the module has and a lot of functionalities that this product has to use (MQTT + TLS + BLE + MP3 + RAW stream), I was force to use all the init and deinit functions available. To focus in the minimal resources that the module has to use:
- MQTT (with TLS and WIFI) or BLE
- MP3 or RAW stream (note that I2S could be always enabled)
- 1 TCP connection (when RAW stream is used, a UDP socket is required)

All the time, a timer is monitoring the free heap memory with "heap_caps_get_free_size(MALLOC_CAP_8BIT)" function.

When the program begins, the total HEAP memory is 228KB.
Then, I initialize the common audio components (I2S). 203KB remaining.
After WIFI get an IP, only 166KB of memory is accesible.
When MQTT with TLS are totally connected with the broker, only 110KB of can be used.

Here is where the problem appears.
1.- After a single play of a MP3 track, a ~1KB of memory is lost.
2.- After a session of RAW stream, a ~25KB of memory is lost.

So, after some usage of the application a restart is needed because there is enough memory to be allocated with a malloc call.

All the init and deinit functions are executed and the sockets (UDP in this case) is properly finished. You can find attached the library that I've being used to init and deinit all the components.

Is there any problem with the memory allocation?
Is there any possibility to remove all the malloc calls?
How can I contain the memory usage of all this issue?
What do you recommend me?


Thanks so much.

Re: Memory leak when using RAW, Filter and I2S.

Posted: Tue Feb 23, 2021 3:38 am
by jason.mao
Hi Ismael,

How about this issue?