I am having trouble deleting an object that is derived from the handle class.
The object 'A' holds handles to several other objects that are derived from the handle class and these may have a handle to the object 'A' and handles between themselves.
I created a delete method for the class of object 'A' that:
-removes all stored handles from all objects that 'A' has handles to (by setting them to [])
-call all delete methods of the objects 'A' has handles to
-remove all handles from 'A' to these objects (by setting them to []). At this point these are handles to deleted classes.
-call 'clear AllObjectHandles'
After I call the delete method I am able to call 'clear classes' without recieving the warning "Objects of 'class_something' class exist. Cannot clear this class or any of its super-classes." (getting rid of another problem I had ;) ).
But only after I execute 'clear classes' the memory usage is roughly as before the object existed.
Just calling the delete method leaves the object in the workspace with the following status:
A
A =
deleted class_something handle
Methods, Events, Superclasses
Memory usage is stable and something like this (I did 5 cycles without restarting Matlab):
load 'A.mat' +100mb
A.delete -25mb
clear classes -75mb
The points that question me:
1. Why does 'A' still exist after I called delete (the destructor)?
2. Why do I have to execute 'clear classes' to free the memory?
3. Why is the delete method not called when I assign a new value to 'A' like "A=1;" although the documentation says so? (or maybe I am getting it wrong)
http://www.mathworks.com/help/techdoc/matlab_oop/brfylzt-1.html#brfylzt-6
Regarding point 2 I have the theory that all the objects that 'A' holds handles to, are not really deleted or destroyed because 'A' still has handles to them, when I call their delete methods. The problem is that I can't call their delete methods anymore, if I delete the handles first because in that case I can't reach them anymore (?).
Thanks
Thomas
PS: Using Matlab R2010b