Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Difficulty using 'clear classes'

76 views
Skip to first unread message

Steve

unread,
Mar 27, 2008, 2:10:04 PM3/27/08
to
Hello, I'm having some trouble clearing the classes (Using
r2008a) when I make a change. When I type clear classes I
get several messages like:

Warning: Objects of 'SomeClassIWrote' class exist. Cannot
clear this class or any of its super-classes.

'clear all' doesn't report any warnings but it also doesn't
actually clear the classes because I still get the same
error if I type 'clear classes' again. The handles seem to
be getting lost somewhere. They're not in referenced in
persistent or global variables and are not in my workspace.

Is there a way I can get all handles to delete them
properly? Like a h=findobj() that works for all handles
rather than just handle graphics? What should I do to
prevent this problem, I thought Matlab's garbage collection
was supposed to take care of this?

Thank you,
Steve

Dave Foti

unread,
Mar 28, 2008, 10:53:18 AM3/28/08
to
Hi Steve,

The "clear classes" first executes a "clear all" and then clears any classes
with no outstanding instances. "clear all" does not itself attempt to clear
any classes which is why you don't see any warnings. It sounds like you
have already checked the most likely places for objects to be kept (global
or persistent variables). If you are using any graphics or Java objects,
your objects could also be held by callbacks or in UserData of those
objects. There is no way to get a list of all objects you create, but they
are not supposed to persist if no longer referenced from anywhere.

-Dave

-----------------------------------------------------------

Dave Foti The MathWorks

Dave...@mathworks.com www.mathworks.com

"Steve " <chestnut...@ensco.com> wrote in message
news:fsgnts$f1d$1...@fred.mathworks.com...

Joe

unread,
Mar 28, 2008, 11:43:02 AM3/28/08
to
Hi Steve,

there might be a problem with your property definitions. Do
you initialize a property to an anonymous function? It
seems you cannot do that. The function handle keeps a
reference to the workspace in which it was created and
therefore contains a reference to the object you are
creating. The "clear all" command misses clearing this
reference, so "clear classes" will fail.

Here is an example of this behavior:

classdef TestClearClass

properties
f = @(x) x;
end

methods
end
end

In the command window:
>> c = TestClearClass;
>> clear classes
Warning: Objects of 'TestClearClass' class exist. Cannot

clear this class or any of its super-classes.


Hope this helps,
Joe

"Steve " <chestnut...@ensco.com> wrote in message

<fsgnts$f1d$1...@fred.mathworks.com>...

Steve

unread,
Mar 28, 2008, 12:08:02 PM3/28/08
to
I don't use any anonymous function handles for initializing
properties though I do use other class constructors like

classdef class2 < handle

properties
aprop = class1();
end

end

But I don't think that should cause any problems. I'm
putting together an example that I can distribute, I'll post
it here when I finish it.

Thanks,
Steve

Jan Hurst

unread,
May 25, 2008, 10:52:39 PM5/25/08
to
Was there any solution to this?

I am running into the same problem. I also am using other class
constructors in initializing properties. Later i may do something like;

class2.aprop = myClass1Instance;

Does this lose the original handle/reference such that clear all can't
find it?

Jan

per isakson

unread,
Jun 9, 2008, 6:29:02 PM6/9/08
to
"Dave Foti" <d...@mathworks.com> wrote in message <fsj0p2
$oeh$1...@fred.mathworks.com>...

> Hi Steve,
>
>
>
> The "clear classes" first executes a "clear all" and then
clears any classes
> with no outstanding instances. "clear all" does not
itself attempt to clear
> any classes which is why you don't see any warnings. It
sounds like you
> have already checked the most likely places for objects
to be kept (global
> or persistent variables). If you are using any graphics
or Java objects,
> your objects could also be held by callbacks or in
UserData of those
> objects. There is no way to get a list of all objects
you create, but they
> are not supposed to persist if no longer referenced from
anywhere.
>
>
>
> -Dave
>
> ----------------------------------------------------------
-
>
> Dave Foti The MathWorks
>
> Dave...@mathworks.com
www.mathworks.com
>

I tried the example of the new FEX-contribution, "Yet
Another Layout Manager" and now it seems it left objects
that I cannot clear.

/ per

Copy from the command window :

>> inmem
ans =
'workspacefunc'
'imformats'
'arrayviewfunc'
>> clear all, clear classes
Warning: Objects of 'RE_Tabpane' class exist. Cannot clear

this class or any of its super-classes.

Warning: Objects of 'RE_Axis' class exist. Cannot clear

this class or any of its super-classes.

Warning: Objects of 'RE_Button' class exist. Cannot clear

this class or any of its super-classes.

>> version
ans =
7.6.0.324 (R2008a)
>>

0 new messages