[Newbies] Get rid of an object
peace_the_dreamer at yahoo.com
Tue Feb 2 02:26:42 UTC 2010
There are several aspects to your question that need answering.
First, the garbage collector will remove any object that is not referenced by another object.
Each time you doit in a workspace you will create a new object.
Each time you assign that object to a variable it will replace the old object in that variable. The old object may at this point have no more references. Then it will be garbage collected.
Second, in the workspace menu there is an item
choosing this causes that workspace to forget all of the variable assignments it was remembering because of doits. Then they may have no other references and be garbage collected.
Thirdly, one of my favorite styles of programming is to save my current work in projects. This saves code, morphs, browsers that are associated with my project. Later I load them back in to a fresh image. The context is that I am trying to always run the project in a fresh environment to assure against contamination from other work. Or to insure that the project works in a fresh system update. In this context it is wise to clean up my project before I save it. That way it has the best chance of reloading over an externally changing system environment.
So I have a big red button. In it I put the following mouse up code:
(SystemWindow windowsIn: World satisfying: [:w | w model canDiscardEdits and: [ w model notNil ] ])
do: [:w | w delete] .
World submorphsDo: [:each |
each model class = Workspace ifTrue: [ each model initializeBindings ] ] .
The first part removes any browsers etc that I am finished with.
The second resets all my workspace variables. That way I don't save my temporary references. This is what you were concerned with.
For the button I use a starmorph reshaped into a hexagon and recolored to be red. The red halo menu>extras>addMouseUpAction allows me to place the action into the star.
In the USA a red hexagonal sign is the symbol for a stop sign. I make the button look like that so I remember to think twice before pressing it. But if I am about to save a project I want things sparse and clean.
Yours in curiosity and service, --Jerome Peace
--- On Mon, 2/1/10, lanas <lanas at securenet.net> wrote:
> From: lanas <lanas at securenet.net>
> Subject: Re: [Newbies] Get rid of an object
> To: "A friendly place to get answers to even the most basic questions about Squeak." <beginners at lists.squeakfoundation.org>
> Date: Monday, February 1, 2010, 7:45 PM
> Le Lundi, 1 Février 2010 19:39:06
> 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
> entities. I'd have thought that perhaps doing a 'do
> it' on myCar a
> second time would have re-initialized the first existing
> If I create 25 myCar for various tests, then there'll be 25
> objects laying around in the image ? How to get rid
> of them ?
> Beginners mailing list
> Beginners at lists.squeakfoundation.org
More information about the Beginners