Clearing a particular class definition from memory

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

 채택된 답변

per isakson
per isakson 2014년 2월 4일

0 개 추천

myclass.prop is possible because Constant=true. It doesn't require the class to be in memory. obj=myclass; is not needed.

댓글 수: 4

Matt J
Matt J 2014년 2월 4일
편집: Matt J 2014년 2월 4일
Hi per,
Yes, I know that. My question, though, is how to clear the property from memory, along with the rest of the class definition, without the nuclear bomb that is 'clear classes'. The property consumes no memory until the class is first referenced and I'd like to return to that state.
Yes, it might be me not understanding your question. However, I think the example below shows that clear myclass works as expected. At least, inmem indicates that.
>> clear all, clear classes
>> myclass.prop
ans =
17
>> inmem
ans =
'codetools\private\dataviewerhelper'
'workspacefunc'
'onCleanup'
'myclass'
>> clear myclass
>> inmem
ans =
'codetools\private\dataviewerhelper'
'workspacefunc'
'onCleanup'
with
>> version
ans =
8.1.0.604 (R2013a)
OK, silly mistake on my part. The very act of inspecting myclass.prop reloads it into memory!
Thanks.
Matt J
Matt J 2014년 2월 4일
편집: Matt J 2014년 2월 4일
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.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Handle Classes에 대해 자세히 알아보기

질문:

2014년 2월 4일

편집:

2014년 2월 4일

Community Treasure Hunt

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

Start Hunting!

Translated by