NVS memory leak - nvs_pagemanager using too much memory

bearchun
Posts: 2
Joined: Sat Jul 01, 2017 3:52 am

NVS memory leak - nvs_pagemanager using too much memory

Postby bearchun » Wed Aug 02, 2017 6:41 am

So, this is not a real memory leak but it will use too much memory for my app to run. When my app is fully functional, it has BLE running and aws mqtt connection. At this point, I have about 70KB of free heap available. But if I continue to read/write into NVS, I will loose lot of memory to a point where my app will crash.

If my NVS partition is very small like 24KB, this is NOT a problem. But if my NVS is large like 2MB, this becomes a real problem. In the NVS code, I think data structures inside "nvs_pagemanager.cpp" is growing as I repeat read/write into NVS.

Here is the code that will reproduce this problem:

https://drive.google.com/open?id=0B8IOF ... 2ttWmdBR1U

After downloading you can build with these commands to reproduce leak case and no leak case.
Again, this is NOT really a leak, but it just uses too much memory.

To reproduce LEAK case:

Code: Select all

  make defconfig SDKCONFIG_DEFAULTS=sdkconfig.leak.defaults
  make
  make erase_flash flash
To reproduce NO LEAK case:

Code: Select all

  make defconfig SDKCONFIG_DEFAULTS=sdkconfig.noleak.defaults
  make
  make erase_flash flash
Is it possible to add some kind of nvs_flush() function I can call so it clears the nvs_pagemanager after I am done writing to NVS?

ESP_igrr
Posts: 2072
Joined: Tue Dec 01, 2015 8:37 am

Re: NVS memory leak - nvs_pagemanager using too much memory

Postby ESP_igrr » Wed Aug 02, 2017 8:08 am

If you need a lot of storage (more than few tens of kB), i suggest you to consider using a file system (such as FAT or SPIFFS) instead of NVS. NVS does not scale well for large partition sizes.

Who is online

Users browsing this forum: No registered users and 84 guests