Suppose I have a class myClass < handle
. From the Mathworks Help page on clear
,
Clearing handle graphics handles does not remove the objects themselves, nor does deleting the objects remove variables storing their handles.
hf = figure; % Creates figure object, stores handle in variable hf
delete(hf) % Removes figure object, but not the variable hf
clear hf % Removes hf from the workspace; figure could still exist
So clear
ing a handle object does not remove it from memory unless I explicitly delete
it first..
I specified a destructor for myClass
to do proper cleanup and remove some references to it; this destructor is not called upon clear
. Is it possible to call that destructor when my object is cleared?
EDIT: I should mention that while delete
is automatically called with a clear
if there are no references to the myClass
object, I have another class, say myOtherClass
with properties that refer to myClass
, say myOtherClass.a
. There are additionally other properties in myOtherClass
that aren't properties of myClass
, but they should be empty if myOtherClass.a
is also empty. Let me know if that doesn't make sense, that might have been a bit too wordy.