MATLAB Answers

How To Clear Java Heap Space Memory????

387 views (last 30 days)
Mike
Mike on 25 Jul 2011
Answered: Luke Perry on 5 Mar 2019
How to deal with "Java Heap Space Outofmemroyerror" seems to be a commonly asked question. I am using Matlab R2011a, and one solution is to increase the java Heap Size, which can be done at: File -> Preferences -> General -> Java Heap Memory.
My wondering is, is there any command like "clear STH " that can clear the Java Heap Space Memory, just like "clear all" clears the whole matlab workspace, so Java Heap Memory can always be freed when needed.
I thought "clear java" will do the trick. But it turns out "clear java" functions almost the same as "clear all", exept that it also clears all java classes... What i am looking for is something that will only clear memory of Java heap and preserve all other variables.
Anybody here knows how to do this trick?
Thanks.

  3 Comments

David Goldsmith
David Goldsmith on 29 Aug 2012
I'm (newly) encountering the error in a DB query in an application which, ultimately, gets compiled--is there a "functional" way to execute the File->Preferences-> General-> Java Haap Memory sequence so that my compiled application can do it when necessary? Thanks!
Patrik Ek
Patrik Ek on 3 Feb 2014
I have also encountered this problem. Can it be concluded that this is no longer possible? Also are there any way to contact mathworks to contact mathworks directly on this issue. It seems that some updates or documentation are needed for this issue.
Sunil
Sunil on 24 Sep 2014
Any solution ! facing same issue since 2010

Sign in to comment.

Answers (14)

Jason
Jason on 28 Jul 2011
I have this same problem. In earlier versions of Matlab 2010b etc, clear java just cleared the heap space as you suggested, but as of 2011a clear java clears just about everything. This change broke a bunch of my code. I look forward to a solution.

  0 Comments

Sign in to comment.


Jakob Sievers
Jakob Sievers on 26 Jun 2012
I would like to join in the choir of people looking for a solution to this. Primarily to bump this thread back to the top of the discussion.
Cheers

  0 Comments

Sign in to comment.


Arthur
Arthur on 16 Jul 2013
Seeing as how the question is still not answered I would to comment to get it back on top. I'm using matlab r2013a and I can't find a way to clear the java heap space.
cheers

  0 Comments

Sign in to comment.


Karthik Vantakala
Karthik Vantakala on 26 Mar 2014
Looking for a solution as well, bump!

  0 Comments

Sign in to comment.


Andre Silva
Andre Silva on 20 Aug 2014
Also looking for an answer!

  0 Comments

Sign in to comment.


Sunil
Sunil on 24 Sep 2014
Do we have any solution? I am struggling with this problem since 2010 !!

  0 Comments

Sign in to comment.


Adam Neufeldt
Adam Neufeldt on 10 Mar 2016
I also am looking for a solution

  0 Comments

Sign in to comment.


Michael
Michael on 2 Aug 2016
I use this (but I'm not sure it works on my mac--mavericks):

  0 Comments

Sign in to comment.


jessica grazziotin
jessica grazziotin on 11 Jul 2017
Same question!! Thank you.

  0 Comments

Sign in to comment.


Jim Bosley
Jim Bosley on 15 Aug 2018
Edited: Walter Roberson on 4 Mar 2019
This error kept me from publishing completed work. That is, Matlab did the analysis, but publish could not complete for the script.
I recently ran sbiofit. Got an answer. Plotted the results. Then I got an error in publishing the result, because of this issue.
I've tried reallocating more heap space. See https://www.mathworks.com/help/matlab/matlab_external/java-heap-memory-preferences.html . This did not work. A bummer, because Matlab completed the analysis, but couldn't publish the result in a pdf. FWIW, the heap size allocation is synopsized below: I hope that this works better for you all than for me.
Basically go to Environment tab and increase heap in Preferences > MATLAB > General > Java Heap Memory. Restart.
Error using evalmxdom>populateDom (line 246) Java exception occurred: java.lang.OutOfMemoryError: Java heap space
Error in evalmxdom (line 46) populateDom(dom,data,text,laste)
Error in publish
Error in mdbpublish (line 55) outputPath = publish(file, options);
Error using open (line 52) NAME must be a character vector or string scalar.

  0 Comments

Sign in to comment.


Jonathan
Jonathan on 30 Aug 2018
years are passing on this one folks. hello? Mathworks please address this.

  0 Comments

Sign in to comment.


Luke Perry
Luke Perry on 4 Mar 2019
I'm directly copying and pasting this onto a technical request. I just ran into this problem and there is no way around it.

  0 Comments

Sign in to comment.


Jim Bosley
Jim Bosley on 4 Mar 2019
jonathan wrote: "years are passing on this one folks. hello? Mathworks please address this."
I'm thinking that maybe eight years should be enough time to solve this? :)

  0 Comments

Sign in to comment.


Luke Perry
Luke Perry on 5 Mar 2019
So the official response I recieved from Mathworks is to use this for now:
And an enhancement request has been submitted to add this feature to a future MATLAB release.

  0 Comments

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!