Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memory leak somewhere #15

Open
jfseaman opened this issue Aug 12, 2024 · 5 comments
Open

Memory leak somewhere #15

jfseaman opened this issue Aug 12, 2024 · 5 comments

Comments

@jfseaman
Copy link

There seems to be a memory leak.

Where? Library or in PSRamFS_Test.ino?

I did not audit PSRamFS_Test completely.
I did change all the ESP_LOGx(...) to Serial.printf and fixed the formatting.
I changed it to run in loop() instead of setup() with a halt at the end. I kept setup code in setup. Not much of that.

I tried a Arduino Nano ESP32 (16M flash, 8M PSRAM) and a Espressif ESP32-S3 De Kit N8R8 (8M flash, 8M PSRAM)

The leak is in both.

The biggest annoyance is that the leak is different for each iteration.

It could be as simple as an unpaired create/close. Like I said, didn't do a complete audit of PSRamFS_Test.ino and didn't create a sketch from scratch with more limited use of the library.

The leak is from 0 to 440 byes. Varies each run, each pass through loop.

23:13:16.615 -> Free PSRAM: 8385672
23:13:16.615 -> Running test setup_tesrdown
23:13:16.615 -> running test format_mounted partition
23:13:16.658 -> Free PSRAM: 8385672
...
23:13:19.077 -> Test complete
23:13:19.077 -> Starting_Free_PSRAM (8385672) != ESP.getFreePsram() (8385456)
...
23:14:21.563 -> Test complete
23:14:21.563 -> Starting_Free_PSRAM (8385672) != ESP.getFreePsram() (8385244)
...
23:15:24.009 -> Test complete
23:15:24.009 -> Starting_Free_PSRAM (8385672) != ESP.getFreePsram() (8385032)
...
23:16:26.494 -> Test complete
23:16:26.494 -> Starting_Free_PSRAM (8385672) != ESP.getFreePsram() (8384820)
...
23:17:28.963 -> Test complete
23:17:28.963 -> Starting_Free_PSRAM (8385672) != ESP.getFreePsram() (8384588)

@tobozo
Copy link
Owner

tobozo commented Aug 13, 2024

hi,

thanks for your feedback 👍

folder related functions are probably leaky, does it improve if you limit the tests to read/write/append/rename/delete ?

@jfseaman
Copy link
Author

I don't know. Not tested that way.

I would have to write sketches to specifically test each realm of functions. File, directory, etc... to find the leak.

Or exclude the directory functions from example and see if it goes away.

It will be a couple days to do that.

@tobozo
Copy link
Owner

tobozo commented Aug 14, 2024

yes I meant to just exclude the directory functions from the example

have you tried commenting out this part?

#define UNIT_TESTS

@jfseaman
Copy link
Author

Found it:

Application level error in PSRamFS_test.ino at line 441:
if( ! PSRamFS.setPartitionSize( ESP.getFreePsram()/2 ) ) { // try to allocate half of psram

Change to:
if( ! PSRamFS.setPartitionSize( ESP.getMaxAllocHeap()/2 ) ) { // try to allocate half of psram

No leaks

@jfseaman
Copy link
Author

I'm stress testing it thoroughly ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants