Most elegant way to delete instances

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

Most elegant way to delete instances

Giuseppe
Hi,

I need to delete all the instances of a class. I would like to know,  
wich is the best way to do this.

I'm trying this:
IGCompany allInstances do: [ :each | each := nil].

But this, doesn't works.

All help is appreciated.

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

Re: Most elegant way to delete instances

Randal L. Schwartz
>>>>> "Giuseppe" == Giuseppe Luigi Punzi Ruiz <[hidden email]> writes:

Giuseppe> I need to delete all the instances of a class. I would like to know,  wich is
Giuseppe> the best way to do this.

Giuseppe> I'm trying this:
Giuseppe> IGCompany allInstances do: [ :each | each := nil].

Giuseppe> But this, doesn't works.

Giuseppe> All help is appreciated.

"each := nil" changes the local variable "each" from containing an instance of
IGCompany to holding nil.  That doesn't do anything to the original instance.

You need to find all of the objects *holding* these IGCompany instances and
tell them to let go.  Once everyone has let go of all of them, then the next
garbage collection pass will see that nobody is pointing to them, and get rid
of them.  In normal programming, this should just happen naturally.

The larger question is, why do you care?  I hope you're not writing code that
looks like "IGCompany allInstances" for *real* code.

--
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: Most elegant way to delete instances

Bert Freudenberg
In reply to this post by Giuseppe

Am 14.09.2008 um 20:15 schrieb Giuseppe Luigi Punzi Ruiz:

> Hi,
>
> I need to delete all the instances of a class.

Why?

> I would like to know, wich is the best way to do this.
>
> I'm trying this:
> IGCompany allInstances do: [ :each | each := nil].
>
> But this, doesn't works.


There is no need to "delete instances". When they are not used  
anymore, they will be garbage collected automatically.

- Bert -


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