Clearing a particular class definition from memory

8 views (last 30 days)
I know that `clear classes` will clear all classes from memory, but I cannot find a way to clear one particular class. Entering
>> clear classname
does not work. Is there a way to do this?
In other forums, clearing all instances of the class, either manually or by automated means, has been proposed. This doesn't work however, as the following example shows. The constant property data remains.
classdef myclass
properties (Constant)
prop=17;
end
end
>> obj=myclass; myclass.prop
ans =
17
>> clear obj; myclass.prop
ans =
17

Accepted Answer

per isakson
per isakson on 4 Feb 2014
myclass.prop is possible because Constant=true. It doesn't require the class to be in memory. obj=myclass; is not needed.
  4 Comments
Matt J
Matt J on 4 Feb 2014
OK, silly mistake on my part. The very act of inspecting myclass.prop reloads it into memory!
Thanks.
Matt J
Matt J on 4 Feb 2014
Edited: Matt J on 4 Feb 2014
Footnote. Using the Task Manager, I find that `clear classname` does not clear existing class instances from memory and does not clear Constant property memory while any objects exists. To clear property memory, it is necessary that both, not just one, of the following are done
  1. Clear all class instances
  2. Issue `clear classname`
Moreover, it must be done in the above order. Reversing the order will leave Constant property data stuck in memory (as of R2013b) until `clear classes` is issued.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!