Discussion:
Clear existing objects
(too old to reply)
Stefan
2008-10-01 07:37:01 UTC
Permalink
Hello,

I am debugging some object oriented code.
After exiting the debug mode somewhere in my function I want to get rid of existing objects, so that I can modifiy my class definition files.
I'm using the commands "clear all" and "clear classes" but "clear alls" doesn't delete all objects.

The existing objects can't be seen in the workspace.
How can I delete these objects?
clear all
clear classes
Warning: Objects of 'tdTracePacket' class exist. Cannot clear this class or any of its super-classes.
Warning: Objects of 'tdStation' class exist. Cannot clear this class or any of its super-classes.
Warning: Objects of 'tdChannelAxes' class exist. Cannot clear this class or any of its super-classes.
Warning: Objects of 'smUnit' class exist. Cannot clear this class or any of its super-classes.
Warning: Objects of 'tdTrace' class exist. Cannot clear this class or any of its super-classes.
Warning: Objects of uitools.uimodemanager class exist - not clearing this class
or any of its super-classes
Warning: Objects of uitools.uimode class exist - not clearing this class
or any of its super-classes
Warning: Objects of graphics.datacursormanager class exist - not clearing this class
or any of its super-classes
Warning: The following classes still have existing instances that cannot be cleared:
sm_module (77 instances)
sm_flowList (5 instances)
database (1 instance)
sm_flowModule (10 instances)
dbtbx (1 instance)
Thank's
Stefan.
Martin
2008-11-03 07:44:06 UTC
Permalink
I have encountered the same problem when using the Matlab Database toolbox (which is largely based on objects). When I run my code, these objects seem to slowly fill up my RAM until I get an outOfMemory error. If I try a 'clear all', the RAM is just as full, and if I try 'pack', I get errors of this kind:

Warning: ***@baaea8 is not serializable
Warning: ***@20a239 is not serializable
Warning: Could not serialize object: ***@1d2acaf
java.io.NotSerializableException: oracle.jdbc.driver.T4CConnection

The objects disappear and the RAM is cleared when if I do a restart of Matlab. Sorry that I have no fix for your problem, Stefan - I'm just hoping someone else has.

Martin
Steven Lord
2008-11-03 15:06:20 UTC
Permalink
Post by Martin
I have encountered the same problem when using the Matlab Database toolbox
(which is largely based on objects). When I run my code, these objects seem
to slowly fill up my RAM until I get an outOfMemory error. If I try a
'clear all', the RAM is just as full, and if I try 'pack', I get errors of
Make sure you CLOSE the objects created by Database Toolbox before trying to
CLEAR them, or you could potentially be leaving part of the connection
hanging.

http://www.mathworks.com/access/helpdesk/help/toolbox/database/ug/close.html

Once you CLOSE them, you should be able to CLEAR them just like any other
variable.

As for PACK, as it states in its description, it temporarily saves your
workspace data into a file (it serializes the variables.)

http://www.mathworks.com/access/helpdesk/help/techdoc/ref/pack.html
Post by Martin
java.io.NotSerializableException: oracle.jdbc.driver.T4CConnection
It doesn't make sense to serialize a connection to a database (what if that
database was no longer available the next time you loaded that object?)
Therefore, the ability to do so has not been implemented (or it has been
implemented to throw an exception, in the case of the Java
oracle.jdbc.driver.T4CConnnection class.)
--
Steve Lord
***@mathworks.com
Steffen
2008-11-18 10:50:17 UTC
Permalink
Post by Steven Lord
Post by Martin
I have encountered the same problem when using the Matlab Database toolbox
(which is largely based on objects). When I run my code, these objects seem
to slowly fill up my RAM until I get an outOfMemory error. If I try a
'clear all', the RAM is just as full, and if I try 'pack', I get errors of
Make sure you CLOSE the objects created by Database Toolbox before trying to
CLEAR them, or you could potentially be leaving part of the connection
hanging.
http://www.mathworks.com/access/helpdesk/help/toolbox/database/ug/close.html
Once you CLOSE them, you should be able to CLEAR them just like any other
variable.
As for PACK, as it states in its description, it temporarily saves your
workspace data into a file (it serializes the variables.)
http://www.mathworks.com/access/helpdesk/help/techdoc/ref/pack.html
Post by Martin
java.io.NotSerializableException: oracle.jdbc.driver.T4CConnection
It doesn't make sense to serialize a connection to a database (what if that
database was no longer available the next time you loaded that object?)
Therefore, the ability to do so has not been implemented (or it has been
implemented to throw an exception, in the case of the Java
oracle.jdbc.driver.T4CConnnection class.)
--
Steve Lord
Hi Steven,

this only applies to database objects. Whatabout self-defined objects. I got the same error message (see first message in this thread) for user defined classes and objects. Is there a way to define a close function for those objects?

BR,
Steffen
Steffen
2008-12-15 07:48:05 UTC
Permalink
there's really no expert to answer that question ?????
Steve
2009-01-14 19:59:02 UTC
Permalink
Post by Steffen
there's really no expert to answer that question ?????
@Steffen

I found this article that may help:

http://www.mathworks.ch/support/solutions/data/1-6K9BQ7.html?product=ML&solution=1-6K9BQ7


Looks like that's just how Matlab works on this verson. To clear out all objects and reset everything, I've been restarting Matlab. Kind of annoying, but it does the trick.


-Steve
per isakson
2009-01-14 20:24:01 UTC
Permalink
Post by Steffen
there's really no expert to answer that question ?????
See Greg's post in the thread "retart matlab after changing class methods?" a couple of weeks ago.

/per
None
2011-05-11 10:12:02 UTC
Permalink
I am not sure whether this topic is still active, but since I have not found my solution anywhere I will still post it here.

The reason that these classes cannot be cleared is that they are still referenced, even though all objects have been cleared from the workspace. This can happen when two objects store each others handle, e.g.:
A.handle = B;
B.handle = A;
clear A B;

It is best practice to avoid this 'loop' situation. However, if you need it, make sure you keep the handle of at least one of the objects. With the delete command you can then break this loop, e.g.:
A.handle = B;
B.handle = A;
delete(A);
clear A B;
Albert
2011-05-23 17:57:05 UTC
Permalink
I had this problem in some handle classes i created that were linked to each other. Adding a delete method to one of the classes that cleared the contained reference to the other class's object fixed the issue.

obj1.Subsystem = obj2; % obj1 is class system
obj2.System = obj1; % obj2 is class subsystem

function delete(obj2) % subsystem.delete
obj1.system=[];
end
Post by None
A.handle = B;
B.handle = A;
delete(A);
clear A B;
Fourat
2014-03-20 10:17:18 UTC
Permalink
Post by Stefan
Hello,
I am debugging some object oriented code.
After exiting the debug mode somewhere in my function I want to get rid of existing objects, so that I can modifiy my class definition files.
I'm using the commands "clear all" and "clear classes" but "clear alls" doesn't delete all objects.
The existing objects can't be seen in the workspace.
How can I delete these objects?
Post by Stefan
clear all
clear classes
Warning: Objects of 'tdTracePacket' class exist. Cannot clear this class or any of its super-classes.
Warning: Objects of 'tdStation' class exist. Cannot clear this class or any of its super-classes.
Warning: Objects of 'tdChannelAxes' class exist. Cannot clear this class or any of its super-classes.
Warning: Objects of 'smUnit' class exist. Cannot clear this class or any of its super-classes.
Warning: Objects of 'tdTrace' class exist. Cannot clear this class or any of its super-classes.
Warning: Objects of uitools.uimodemanager class exist - not clearing this class
or any of its super-classes
Warning: Objects of uitools.uimode class exist - not clearing this class
or any of its super-classes
Warning: Objects of graphics.datacursormanager class exist - not clearing this class
or any of its super-classes
sm_module (77 instances)
sm_flowList (5 instances)
database (1 instance)
sm_flowModule (10 instances)
dbtbx (1 instance)
Thank's
Stefan.
I have similar problem. I fixed the problem by deleting 'clear classes' and instead I put 'clear obj1 obj2 obj3.....'. In fact it works.
try it

Loading...