Removing 'dead' instances

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Removing 'dead' instances

Andy Burnett
Could some kind soul please explain what I am doing wrong here?

I have a model, called Fspace, which I have created several instances of, whilst I was testing it.

Fspace allInstances size reports 9 instances.

When I run

Fspace allInstancesDo:
   [:each |
   each := nil.
Transcript show: (each value); cr.
   Smalltalk garbageCollect]

The transcript shows that the values are set to nil. However, the instances don't go away.  So, what am I doing wrong?

Cheers
AB

_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: Removing 'dead' instances

Randal L. Schwartz
>>>>> "Andy" == Andy Burnett <[hidden email]> 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 of,
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 instances
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".

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
<[hidden email]> <URL:http://www.stonehenge.com/merlyn/>
Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
See http://methodsandmessages.vox.com/ for Smalltalk and Seaside discussion
_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: Removing 'dead' instances

Tapple Gao
In reply to this post by Andy Burnett
On Sun, Sep 28, 2008 at 12:08:15PM -0400, Andy Burnett wrote:

> Could some kind soul please explain what I am doing wrong here?
>
> I have a model, called Fspace, which I have created several instances of,
> whilst I was testing it.
>
> Fspace allInstances size reports 9 instances.
>
> When I run
>
> Fspace allInstancesDo:
>    [:each |
>    each := nil.
> Transcript show: (each value); cr.
>    Smalltalk garbageCollect]
>
> The transcript shows that the values are set to nil. However, the instances
> don't go away.  So, what am I doing wrong?
>
> Cheers
> AB

> _______________________________________________
> Beginners mailing list
> [hidden email]
> http://lists.squeakfoundation.org/mailman/listinfo/beginners

try closing your workspaces

--
Matthew Fulmer -- http://mtfulmer.wordpress.com/
_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: Removing 'dead' instances

Marcin Tustin
In reply to this post by Andy Burnett


On Sun, Sep 28, 2008 at 5:28 PM, Randal L. Schwartz <[hidden email]> wrote:
>>>>> "Andy" == Andy Burnett <[hidden email]> 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 of,
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 instances
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
<[hidden email]> <URL:http://www.stonehenge.com/merlyn/>
Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
See http://methodsandmessages.vox.com/ for Smalltalk and Seaside discussion
_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners


_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: Removing 'dead' instances

Andy Burnett
In reply to this post by Andy Burnett
<<< Randal said...
Setting "each" to "nil" there does nothing, since you aren't
updating the object that was originally in "each".
>>>

<< Marcus said...
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.>>

I was wondering exactly that myself. After my 'doh!' moment, when Randal explained what I was doing wrong, I was trying to work out why I had made the mistake. The conclusion I came to was that I was becoming so used to sending messages to objects, that I had confused myself into thinking that I was somehow sending 'become nil' to the object stored in :each.

Cheers
AB



_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: Re: Removing 'dead' instances

Randal L. Schwartz
>>>>> "Andy" == Andy Burnett <[hidden email]> writes:

Andy> I was wondering exactly that myself. After my 'doh!' moment, when Randal
Andy> explained what I was doing wrong, I was trying to work out why I had made
Andy> the mistake. The conclusion I came to was that I was becoming so used to
Andy> sending messages to objects, that I had confused myself into thinking that I
Andy> was somehow sending 'become nil' to the object stored in :each.

In a system where #become: is a two-way swap, rather than one-way, you *never*
want to send "become: nil".  That'd break everything, since now the value
of "nil" would be your other object. :)
The "safe" way to "become:" something innocent is often "become: String new".
Even so, it's (a) very slow on Squeak and (b) a bit shocking to the holder
of the value, who still expects the old object at its referenced oop.

--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<[hidden email]> <URL:http://www.stonehenge.com/merlyn/>
Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
See http://methodsandmessages.vox.com/ for Smalltalk and Seaside discussion
_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners