I have a MATLAB class which contains a reference to a java object
classdef MyClass properties j = myJavaClass end methods ... end end
and after I use it (using clear, scope exit or explicitly setting myClass = 0; ) the java object is still alive – even after calling Runtime.gc.
I see in the dump that the object is still in the JVM heap for the MATLAB process (using jmap -histo pID) and thus I assume MATLAB itself is still referencing the object – despite calling to clear, clear JAVA, clear classes, etc. – nothing helps
Any ideas?
The workaround gnovice suggested seem to work – adding to the destructor the line
Caused the object not to be present in MATLAB’s JVM heap.
It look like a bug in MATLAB that causes the referencing of the JAVA objects in unreferenced MCOS classes.