Matlab memory use increases every time I run my script
14 views (last 30 days)
Show older comments
Whenever I run my script MATLAB.exe increases in size by several hundred Mbytes, as reported by the Windows resource monitor. After a few trials my memory is filled.
How do I fix this? Currently I remedy this by closing and restarting Matlab.
I am running Matlab using a 64 bit version of Windows 7 with 8GB of RAM.
0 Comments
Answers (1)
Jan
on 17 Nov 2016
Without seeing any details, it is impossible to guess, what's going on. There is no general "do not let Matlab waste memory" flag. Perhaps your script stores more and more values in a growing array? If you in addition forgot to pre-allocate it (search for the term in this forum in case of doubts), the memory consumption is a problem of your script and not of Matlab. A whos and a feature memstats should reveal some details.
Do you use any C-Mex scripts provided by users?
3 Comments
Steven Lord
on 17 Nov 2016
Show us a SMALL segment of code with which you can reproduce the problem and a SMALL sample of data needed to run that code and we may be able to offer much more specific suggestions.
Jan
on 21 Nov 2016
Matlab does release memory automatically, when it is not used anymore. And the OS will clean this memory automatically as soon as it finds the time to do this. A proper pre-allocation (better reserve too much memory then letting an array grow) reduces the need to cleanup memory and is important for the performance.
The memory might be occupied by persistent variables or by a huge number of objects in a figure. So please show us some code, which reproduces the problem. Otherwise an explicit suggestion would be based on guessing.
See Also
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!