[Newbies] Get rid of an object

Miguel Enrique Cobá Martinez miguel.coba at gmail.com
Tue Feb 2 01:46:37 UTC 2010

El lun, 01-02-2010 a las 19:45 -0500, lanas escribió:
> Le Lundi, 1 Février 2010 19:39:06 -0500,
> lanas <lanas at securenet.net> a écrit :
> >   When creating and testing objects in the Workspace, what is the
> > procedure for getting rid of any ?  
> I noticed that if I create the following and inspect it:
> myCar := Car new.
> myCar setCompany: 'Renault'.
> myCar addEngine: 'Renault V4'.
> myCar addDriveTrain: 'Renault DriveTrain'.
> myCar will have these variables set.
> Now, if I 'do it' once more on the first line the inspect window will
> still show the same variables being set.  If I open another inspect
> window on myCar I get the new object, without any variables yet set.
> So it looks like objects of the same name are considered separate
> entities.  I'd have thought that perhaps doing a 'do it' on myCar a
> second time would have re-initialized the first existing object.
> If I create 25 myCar for various tests, then there'll be 25 myCar
> objects laying around in the image ?  How to get rid of them ?

No, the moment you inspect it (i) a certain code like the one you show,
the Inspector windows is holding a reference to the object being
inspected (and by transitivity, to the objects referenced by it).

If, with the inspect windows open, you save and close the image, the
object is persisted, that is, isn't garbage colected because there is a
reference to it.

If you, instead, close the inspector window, then the object created by
your code isn't referenced by anything (pay attention that the code you
show is just text characters and not an object. The object is created
after the do it compiles it and *evaluates* it) so the object is garbage
collected. So if you save the image, the image will not have the object

the same if you create hundred thousand objects, store them in a
collection and the the collection is thrown away.

The key here is that someone else must reference them in order to
persist. The Garbage collector can detect cyclic references so that they
are also collected (i.e, objA references objB and objB references objA,
the both will be garbage collected).

If you want to persist some object you can use class variables, because
they are part of the class singleton and therefore persisted together
with the class. This is used often to create image-based persistency.

> Al
> _______________________________________________
> Beginners mailing list
> Beginners at lists.squeakfoundation.org
> http://lists.squeakfoundation.org/mailman/listinfo/beginners

Miguel Cobá

More information about the Beginners mailing list