4

A few days ago I began encountering a java.lang.OutOfMemoryError: Java heap space exception on startup of MATLAB - before I run any piece of code or add anything to the path. The default directory MATLAB loads also has no files on it.

I am running MATLAB R2012a on Windows 7 64 bit.

What could be causing this?

2
  • 2
    What platform are you on? Commented Feb 25, 2013 at 12:02
  • 2
    @L0j1k - I am on Windows 7. Silly of me to forget, I'll add it to the question. Commented Feb 25, 2013 at 12:05

3 Answers 3

1

Start your application using java -Xmx -Xms option provide -

-Xmx <number> : max memory allocation to app
-Xms <number> : Min memory at startup
Sign up to request clarification or add additional context in comments.

1 Comment

More specifically: java -Xmx1800m will start the JVM with a maximum memory allocation of 1.8GB. By defauly, the JVM starts with -Xmx256m.
1

To set 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, however:

Note: Increasing the Java heap size decreases the amount of memory available for storing data in arrays.

I guess this means that Matlab doesn't store arrays in its Java heap space. But does this matter if we are just setting the upper limit? I don't think so. More specifically, looking at what happens when I set the above slider to 36 GB, Matlab starts up and immediately its virtual memory (as seen with top) goes to 39.9 GB. But physical memory use is only around 300 MB. So, unless it actually puts something in that heap space, there won't be less physical memory available to e.g. arrays. So it looks like this warning 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.

Comments

0

Refer this How do I increase the heap space for the Java VM in MATLAB 6.0 (R12) and later versions? EDIT -Xms sets the initial size of the heap. Changing this will have no effect on java.lang.OutOfMemory errors. The option to use is -Xmx which sets the maximum size of the heap. See here for details.

2 Comments

It is on startup i.e before I do anything to use up the heap space... moreso I am on 64-bit so I doubt that is the problem
@noam -Xms sets the initial size of the heap

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.