classdef myClass < handle properties (Access = private) pointerObjects = []; end methods (Access = public) function obj = myClass() obj.setPointers(); end function setPointers(obj) obj.setPointers.p1 = libstruct( [..]); obj.setPointers.p2 = libpointer( [..]); end function clearPointers(obj) clear obj.setPointers.p1; clear obj.setPointers.p2; clear obj.setPointers; end end end
I have a custom class myClass, which is defined as a handle class. The method setPointers creates some libstruct and libpointer objects and stores them in a property. This works fine. However, I can not clear/free these objects to successfully unload the DLL, to which the structs and pointers belong.
If I call the method clearPointers, the objects are cleared in clearPointers workspace, but when the the function is left, they are still present in the instance of the myClass object. This causes unloadlibray to terminate with the error "outstanding objects".
I expected, that the clear does clear the objects in the myClass instance and not only in the methods workspace because myClass is derived from the handle class.
How can I clear those objects (and only those)?
Regards Jannis
Best Answer