How To Clear Java Heap Space Memory????

185 ビュー (過去 30 日間)
Mike
Mike 2011 年 7 月 25 日
編集済み: Yair Altman 2021 年 1 月 1 日
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 件のコメント
Patrik Ek
Patrik Ek 2014 年 2 月 3 日
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 2014 年 9 月 24 日
Any solution ! facing same issue since 2010

サインインしてコメントする。

回答 (15 件)

Yair Altman
Yair Altman 2021 年 1 月 1 日
編集済み: Yair Altman 2021 年 1 月 1 日
Clearing Matlab's Java heap space has been long awaited, but I'm afraid that the suggested submission (Davide Tabarelli's JavaHeapCleaner) does nothing more than (1) clear the Swing (GUI) repaint buffer, and (2) run a Java garbage collection. This is just band-aid, that does not help with the basic problem of Matlab's internal memory leaks. It is not much more useful than the notorious pack command.
For those interested, this utility in replicated by the following short Matlab script, which does not require any download or JAR-file installation:
rm = javax.swing.RepaintManager.currentManager([]);
dim = rm.getDoubleBufferMaximumSize();
rm.setDoubleBufferMaximumSize(java.awt.Dimension(0,0)); % clear
rm.setDoubleBufferMaximumSize(dim); %restore original dim
java.lang.System.gc(); % garbage-collect
Note: if your program does not use GUI, then only the last line is relevant for you: java.lang.System.gc()
I'm not disparaging this utility's attempt - I'm just saying that the core problem of memory leaks lies within Matlab's internals, and should be fixed by MathWorks.

Jason
Jason 2011 年 7 月 28 日
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.

Jim Bosley
Jim Bosley 2018 年 8 月 15 日
編集済み: Walter Roberson 2019 年 3 月 4 日
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.

Jakob Sievers
Jakob Sievers 2012 年 6 月 26 日
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

Arthur
Arthur 2013 年 7 月 16 日
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

Karthik Vantakala
Karthik Vantakala 2014 年 3 月 26 日
Looking for a solution as well, bump!

Andre Silva
Andre Silva 2014 年 8 月 20 日
Also looking for an answer!

Sunil
Sunil 2014 年 9 月 24 日
Do we have any solution? I am struggling with this problem since 2010 !!

Adam Neufeldt
Adam Neufeldt 2016 年 3 月 10 日
I also am looking for a solution

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

jessica grazziotin
jessica grazziotin 2017 年 7 月 11 日
Same question!! Thank you.

Jonathan
Jonathan 2018 年 8 月 30 日
years are passing on this one folks. hello? Mathworks please address this.

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

Jim Bosley
Jim Bosley 2019 年 3 月 4 日
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? :)

Luke Perry
Luke Perry 2019 年 3 月 5 日
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.

カテゴリ

Help Center および File ExchangeIntroduction to Installation and Licensing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by