Java Heap Cleaner
Simple function cleaning up, at runtime, Java heap memory, thus preventing java OutOfMemory error
Author: Davide Tabarelli

Yes, David

I unpacked the Jheadcl function in "C:\Program Files\MATLAB\R2009a\toolbox\jheapcl", added this path to the Matlab path by using "File > Set path" and then added "$matlabroot/toolbox/jheapcl/MatlabGarbageCollector.jar" to the last line of the file classpath.txt which is in "C:\Program Files\MATLAB\R2009a\toolbox\local".

However, every now and then, Matlab halts and delivers messages like:

java.lang.OutOfMemoryError: Java heap space
at com.mathworks.jmi.OpaqueJavaInterface.getExceptionMessage(OpaqueJavaInterface.java:1305)
??? Error using ==> set
Failed to retrieve Exception Message

Exception in thread "Timer-1" java.lang.OutOfMemoryError: Java heap space
at java.lang.String.toLowerCase(Unknown Source)
at java.io.Win32FileSystem.hashCode(Unknown Source)
at java.io.File.hashCode(Unknown Source)
at java.util.HashMap.put(Unknown Source)
at com.mathworks.mlwidgets.explorer.control.DocumentContextImpl.getDocumentChanges(DocumentContextImpl.java:457)
at com.mathworks.mlwidgets.explorer.control.DocumentContextImpl.refreshContents(DocumentContextImpl.java:569)
at com.mathworks.mlwidgets.explorer.control.RefreshDaemon$2.run(RefreshDaemon.java:104)
at java.util.TimerThread.mainLoop(Unknown Source)
at java.util.TimerThread.run(Unknown Source)

Did I miss something?

Regards

10 Sep 2012

Java Heap Cleaner
Simple function cleaning up, at runtime, Java heap memory, thus preventing java OutOfMemory error
Author: Davide Tabarelli

I'm using Matlab 7.8.0 (2009a) and have had problems with memory due to Java heap overflow.
So, I tried to follow your guidelines, but ended up with following error messages. Is it because of my Matlab version?

??? Undefined variable "org" or class
"org.dt.matlab.utilities.JavaMemoryCleaner.clear".

Error in ==> jheapcl at 7
org.dt.matlab.utilities.JavaMemoryCleaner.clear(verbose)

As I try to run one of your examples, Matlab (7.8.0 R2009) complains with the following message: "??? Error: File: alphavol.m Line: 78 Column: 3
Expression or statement is incorrect--possibly unbalanced (, {, or [."

Examining the referred line, I see:
[~,rcc] = circumcenters(TriRep(T,X));

It seems that Matlab cannot understand the tilde as an output value. I tried to change it to [cc rcc] = circumcenters... and now Matlab complains about line 194, which reads:
[~,p,r] = dmperm(C);
Again, the tilde seems to be the problem.
By the way, as far I as know, tilde is used as a negation operator in Matlab. What is its use here? Any clue on how to solve this problem?

Thank you very much for this useful code. I have a question, it would be great if you could help. Consider 3D data sampled from the same type of physical object whose shape/size varies from one sample to another, which means the radius as a parameter of triangulation varies across samples as well. What would then be the best criterion for the choice of radius? Any idea(s) would be very helpful. Many thanks in advance.