The tech support at The Mathworks has reproduce the behavior and reported it to the development team. They also provided a script to delete handle objects. I named it c3cleanup.
c3cleanup is useful if the handles are available. Demo:
>> c3m = C3Main( 4 );
>> c3cleanup
>> clear all, clear classes
so far fine! However,
>> c3handle_lost
>> c3cleanup
>> clear all, clear classes
Warning: Objects of 'C3Sub' class exist. Cannot clear this class ...
Warning: Objects of 'C3Main' class exist. Cannot clear this class
>>
where
function c3handle_lost()
c3m = C3Main( 4 );
end
and
%%c3cleanup.m
c3str = who;
for ii = 1 : length(c3str) % for each variable...
if isa( eval(c3str{ii}), 'handle' ) % if it's a HANDLE object or subclass
delete( eval(c3str{ii}) ) % delete the object
clear( c3str{ii} ) % and clear the handle
end
end
.
BTW: EVAL is not always evil!