Skip to Main Content Skip to Search
Login
File Exchange
MATLAB Newsgroup
Link Exchange
  Blogs  
 Contest 
MathWorks.com

Thread Subject: Difficulty using 'clear classes'

Subject: Difficulty using 'clear classes'

From: Steve

Date: 27 Mar, 2008 18:10:04

Message: 1 of 6

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

Subject: Difficulty using 'clear classes'

From: Dave Foti

Date: 28 Mar, 2008 14:53:18

Message: 2 of 6

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.Foti@mathworks.com www.mathworks.com



"Steve " <chestnut.stephen@ensco.com> wrote in message
news:fsgnts$f1d$1@fred.mathworks.com...
> 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


Subject: Difficulty using 'clear classes'

From: Joe

Date: 28 Mar, 2008 15:43:02

Message: 3 of 6

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.stephen@ensco.com> wrote in message
<fsgnts$f1d$1@fred.mathworks.com>...
> 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

Subject: Difficulty using 'clear classes'

From: Steve

Date: 28 Mar, 2008 16:08:02

Message: 4 of 6

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

Subject: Difficulty using 'clear classes'

From: Jan Hurst

Date: 26 May, 2008 02:52:39

Message: 5 of 6

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

Steve wrote:
> 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

Subject: Difficulty using 'clear classes'

From: per isakson

Date: 9 Jun, 2008 22:29:02

Message: 6 of 6

"Dave Foti" <daf@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.Foti@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)
>>

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
object oriented Steve 27 Mar, 2008 14:10:10
classes Steve 27 Mar, 2008 14:10:10
clear Steve 27 Mar, 2008 14:10:10
rssFeed for this Thread

envelope graphic E-mail this page to a colleague

Public Submission Policy
NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Disclaimer prior to use.
Related Topics