[Newbies] Removing 'dead' instances
mm3 at zepler.net
Sun Sep 28 17:25:28 UTC 2008
On Sun, Sep 28, 2008 at 5:28 PM, Randal L. Schwartz
<merlyn at stonehenge.com>wrote:
> >>>>> "Andy" == Andy Burnett <andy.burnett at knowinnovation.com> writes:
> Andy> Could some kind soul please explain what I am doing wrong here?
> Andy> I have a model, called Fspace, which I have created several instances
> Andy> whilst I was testing it.
> Andy> Fspace allInstances size reports 9 instances.
> Andy> When I run
> Andy> Fspace allInstancesDo:
> Andy> [:each |
> Andy> each := nil.
> Andy> Transcript show: (each value); cr.
> Andy> Smalltalk garbageCollect]
> Andy> The transcript shows that the values are set to nil. However, the
> Andy> don't go away. So, what am I doing wrong?
> Setting "each" to "nil" there does nothing, since you aren't
> updating the object that was originally in "each".
This is a pretty common misconception. It seems to come up once a month. I
wonder why - mostly it's not people who are new to programming, who I would
expect to be unfamiliar with the distinction between an object or value and
the location it is stored in.
> You need to tell anyone still holding a reference to your objects
> to let go. Some advice can be found at http://wiki.squeak.org/squeak/2176
> Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
> <merlyn at stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
> Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
> See http://methodsandmessages.vox.com/ for Smalltalk and Seaside
> Beginners mailing list
> Beginners at lists.squeakfoundation.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Beginners