5

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 3

3

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.

2
  • I tried putting to the maximum 795 MB, but it still doesn't work for more than a year .. I think that the problem could be related with other kind of temporary memory, which I don't know how to clean it up for each iteration .. Anyway thanks for the answer E.- Nov 11, 2012 at 17:39
  • Eric, the best way to handle a memory problem safe code in MATLAB is to write modular code i.e. write your functions and avoid Global Variables.
    – Indian
    Nov 12, 2012 at 3:24
0

Memory 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.

1
  • Thanks for the Help. I realized that the structure variable where I was saving all the means was too big, so when i change the name of the output the script run without problems .. Nov 11, 2012 at 23:41
0

Try 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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .