Pages: [1]   Go Down
Author Topic: Memory leak in openNextFile()  (Read 832 times)
0 Members and 1 Guest are viewing this topic.
Simi Valley, CA, USA
Offline Offline
Newbie
*
Karma: 0
Posts: 1
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Looking for a solution to the memory leak in openNextFile()...

When at the end of a directory, the function returns null, but 32 bytes fall into the trans-dimensional vortex, never to be seen again (until reset). 

From what I understand, the memory is malloc'd when a file is opened, but if it is destroyed before closing, the allocation is lost.  In this case, the file is never really opened, so of course it can't be closed.

To make sure I wasn't just being a knucklehead, I checked by adding a FreeRam() call before and after the printDirectory() call in the "listfiles" example of the SD library.  The issue is present, repeatable and deterministic in the example program as well.  My SD card has 3 directories.  The free RAM before the printDirectoy() call was 1001B and it was 905B after.  Add a directory, and 32B additional memory is gone.

I'll try to track this down in the library, but I'm a noob so I'm not especially hopeful... :-P
Logged

0
Offline Offline
Edison Member
*
Karma: 64
Posts: 1636
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

This is a well known problem with the listFiles example and has been around for more than a year.

In general memory is lost unless a File object is closed before doing another open.

This is due mostly to poor design of the SD.h wrapper for SdFat. 

Maybe at some point the Arduino company will fix it.

You can find many posts about this problem in the forum.
Logged

Pages: [1]   Go Up
Jump to: