Inability to clear object definition - nonfunctional "clear classes"

26 ビュー (過去 30 日間)
Greg
Greg 2012 年 9 月 13 日
I'm having an issues with a class that I've written. The class is a subclass of another class which is itself a handle class. Whenever I create an object of this class, the class definition becomes permanently loaded into Matlab and I can't clear it via any method that I can come up with other than restarting Matlab altogether. This means that if I change the class definition in a major way (adding a new method or changing the number of inputs or outputs of a method), I have to restart Matlab to use the changes.
The superclass that this class inherits does not appear to exhibit this behavior.
oo = CLASSNAME();
clear all
clear classes
The " clear classes " generates this warning:
Warning: Objects of 'CLASSNAME' class exist. Cannot clear this class or any of its superclasses.
Then I make a new object:
oo = CLASSNAME();
Which, if I have modified the class definition, generates this warning:
Warning: The class file for 'CLASSNAME' has been changed, but the change cannot be applied because objects based
on the old class file still exist. If you use those objects, you might get unexpected results. You can use the
'clear' command to remove those objects. See 'help clear' for information on how to remove those objects.
Anyone seen anything like this before? Or have any idea what is going on? My hunch is that Matlab isn't destroying the object like it should because it thinks some variable is still referencing that object, but I don't have custom delete() methods defined for either class, so I don't know how I could have broken Matlab's object deletion.
  2 件のコメント
Jim Hokanson
Jim Hokanson 2012 年 11 月 7 日
Sean de Wolski
Sean de Wolski 2012 年 11 月 7 日
@Jim, this turned out to be the bug report I described in your thread where an object is loaded from a -v7.3 *.mat file.

サインインしてコメントする。

採用された回答

Sean de Wolski
Sean de Wolski 2012 年 9 月 13 日
編集済み: Sean de Wolski 2012 年 9 月 17 日
Your hunch is correct!
clear() does not destroy the object, it only clears the handle to the object. This is the exact same as:
h = figure;
clear
The figure is still open but h is gone.
As long as the classes inherit from handle, they will have a factory delete method, make sure to delete them:
delete(h);
clear(h);
More
This can occur in R2012b if objects are saved in -v7.3 format files. When the file is read in, this warning will occur until a fresh session of MATLAB is started. Be sure to use -v7 when saving MAT files with objects in R2012b
  5 件のコメント
Greg
Greg 2012 年 9 月 13 日
Oh, what do you know... I'm currently running R2012b (and have been running the prerelease for that for a while). This problem doesn't seem to happen at all in previous versions.
Looking through the R2012b release notes I can't find anything relevant to either of these classes. (They're not Abstract, don't use handle.static, etc).
Greg
Greg 2013 年 4 月 4 日
Accepting Sean's answer as he helped me figure out the problem was related to -v7.3* .mat-files. This is discussed in a bug report which has in theory been fixed in R2013a.

サインインしてコメントする。

その他の回答 (2 件)

Honglei Chen
Honglei Chen 2012 年 9 月 13 日
This normally means your class is still referenced somewhere. The following link may be helpful (the second half directly talks about this warning)
  1 件のコメント
Greg
Greg 2012 年 9 月 13 日
That's a helpful link! This is definitely related to what's going on. The problem is that none of the suggestions seem to be where the class reference is hiding. I don't have any figures or GUIs open that could be holding a reference. Running a "clear functions" doesn't help. I'm not sure I can guarantee that there aren't locked functions hiding somewhere, but I never use any "mlock" functionality, so I don't know what would have locked a function.

サインインしてコメントする。


Daniel Shub
Daniel Shub 2012 年 9 月 14 日
I think that the list that Honglei provided is incomplete. MATLAB has a number of user-managed data types (see Loren's blog and my follow up question) that can hide an instance of your class.

カテゴリ

Help Center および File ExchangeProgramming についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by