Out of memory on MATLAB
I'm trying to run a script on matlab_2011a, which calculate same means for a climatology of 50 years. When I started to run the script for all the years it worked fine until the iteration 20th, and then appeared the message:
Out of memory. Type HELP MEMORY for your options. Then I used clear v1 v2 v3 ... to clear all the variables inside the function, also i used clear train because i saw it in another forum, and these with the modifications or not, I run again the script (since the 21th iteration), and the result is the same message, but curiously sometimes it run a year and then stop.
Any ideas about solving this problem?, what I have to clean to run correctly? (in this matlab version there's not the command memory which maybe could help me).
EDIT
Solution: There was a variable that was too large, saving the results differently prevented the out of memory error.
3 Answers
I am not an avid MATLAB user, but may I suggest you to try:
File > Preferences > General > Java Heap Memory. Then you can increase the amount of memory beyond the default value of 196 MB. Hope this helps.
2Memory management is a long standing problem for Matlab. The most likely cause of your out of memory error is that there is a memory leak. Memory leaks can be found, but finding them is technically challenging and time consuming.
To completely free up the memory, Matlab needs to be restarted. If there is a way to save the results after processing some of the data, save the data and restart Matlab. Reload the data and process another another chuck of data. Repeat until all the data is processed. The amount of data to process should be less than 20 years.
This is far from elegant and depends on being able to save and reload the data. Also, I assume that the size of the data itself is not the problem.
1Try this, it works well for me.
- Go to Home -> Preference icon -> General -> Java Heap Memory -> Allocate what size of memory you want
- In Preference window, go to "Workspace" (out of Java heap memory level) -> See "Matlab Array size limit" Make sure uncheck the 'Limit the maximum array size to a percentage of RAM'. Because you want to extend memory so we don't need this feature.
- Done.
More in general
"Zoraya ter Beek, age 29, just died by assisted suicide in the Netherlands. She was physically healthy, but psychologically depressed. It's an abomination that an entire society would actively facilitate, even encourage, someone ending their own life because they had no hope. Th…"