java.lang.OutOfMemoryError: Java heap space on startup

前端 未结 3 607
遥遥无期
遥遥无期 2021-01-14 16:51

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 anythin

3条回答
  •  长发绾君心
    2021-01-14 17:37

    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.

提交回复
热议问题