Troubleshooting Memory Leaks in Matlab?
14 views (last 30 days)
Show older comments
I was wondering if anyone knows where to find a good guide on troubleshooting memory leaks specifically ones that happen in matlab. I'm running a Global Optimization and one of the sub-functions that the objective function calls: tests if a file exists, if it doesn't it creates a file then my method uses that file to do some calculations and the deletes the file from the hard drive. This happens 10,000's to 100,000's of times in a 12 hour period while the code runs. system momory is about 2.3 - 3 Gig when started clean with matlab running. After running the algorithm the system memory is about 7 Gig in use. clear all does nothing to change that. closing matlab and waiting 5 minutes and the memory goes back down to the 2.5 - 3 Gig range. I've written other code that does everything but the writing of files and deleting them after calculation, so I assume it has something to do with that.
I'm using fopen, fprintf and fclose to write the file and the delete command to delete it from the hard drive.
Any suggestions on how to troubleshoot this and or document it properly for submission of a possible bug report are welcome.
BTW I'm using a windows 7 machine with R2014a.
2 Comments
dpb
on 19 Jun 2014
I'd guess it's actually a fignewton of the OS and "lazy" deallocate/reclamation that the memory is flagged as clear but as long as the application is running there's no opportunity for the OS to actually release it.
Try creating a memmapfile object instead of a disk file -- it may have a better chance of releasing or reusing memory and likely will have better performance besides.
It's always worth a query to official TMW support at www.mathworks.com; particularly if you can cut your code down to a bare-bones app that creates the issue but is small in size--it may be that simply the file creation/deletion alone will demonstrate the issue I'd guess.
Answers (0)
See Also
Categories
Find more on Entering Commands in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!