Reputation: 793
I was hoping that someone on here would be able to explain or point me to a webpage where I could learn more about Matlab's memory management. I know that Matlab is a higher level language so it takes care of memory management, which is good and bad. Good cause I don't need to worry about it and bad cause I have no idea what it is doing under the hood. The reason I ask is lately I've been getting this error message a lot.
Insufficient Java heap memory to continue operation
Granted I'm using a mid 2010 15" Macbook pro, with only 4 GB of RAM, not really the best computer to be perform all the image operations that I do. I know Matlab has a delete function, and I didn't know when/if it would be helpful to use this function to save memory? I have used the delete function before only in hardware related tasks when I am sending data through serial I delete my serial object. But beyond that should I be using delete for my own memory management?
Upvotes: 1
Views: 3808
Reputation: 23593
To set the equivalent of the -Xmx
parameter in more recent versions of Matlab, go to Preferences (on the toolbar/ribbon), then
MATLAB > General > Java Heap Memory
There is a slider there. Matlab will have to be restarted for this to take effect.
There is a warning about doing this, but as I wrote elsewhere, I think it can be ignored.
In case you only have non-graphical access to Matlab through a terminal, the effect of the above command was to add the following line to ~/.matlab/R2016a/matlab.prf
, so you could do that manually instead.
JavaMemHeapMax=I36532
This line appeared after I used the slider to set the preference to 36,532 MB and quit Matlab. If you can't find your matlab.prf
file, check here.
Upvotes: 0
Reputation: 551
See this question. To prevent Java heap error, you will need to change JVM options. Change the default value in Matlab preferences or create a new java.opts
file with -Xmx
(and optionally -Xms
) options, e.g.,
-Xmx1g
Upvotes: 2