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));
rm.setDoubleBufferMaximumSize(dim);
java.lang.System.gc();
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.
3 Comments
Direct link to this comment
https://www.mathworks.com/matlabcentral/answers/12318-how-to-clear-java-heap-space-memory#comment_96653
Direct link to this comment
https://www.mathworks.com/matlabcentral/answers/12318-how-to-clear-java-heap-space-memory#comment_96653
Direct link to this comment
https://www.mathworks.com/matlabcentral/answers/12318-how-to-clear-java-heap-space-memory#comment_194111
Direct link to this comment
https://www.mathworks.com/matlabcentral/answers/12318-how-to-clear-java-heap-space-memory#comment_194111
Direct link to this comment
https://www.mathworks.com/matlabcentral/answers/12318-how-to-clear-java-heap-space-memory#comment_238948
Direct link to this comment
https://www.mathworks.com/matlabcentral/answers/12318-how-to-clear-java-heap-space-memory#comment_238948
Sign in to comment.