[Newbies] terminate event?

abdu chadili a_chadili at yahoo.com
Mon Jan 22 14:38:36 UTC 2007


Or

x := Object new.
x toFinalizeSend: #show: to: Transcript with: 'He''s dead, Jim!\'  withCRs.
Utilities finalize. 
x:=nil.

will display the message to the transcript immediately.

----- Original Message ----
From: David Urquhart <david.urquhart at hotmail.com>
To: beginners at lists.squeakfoundation.org
Sent: Sunday, January 21, 2007 9:42:16 PM
Subject: Re: [Newbies] terminate event?


Thanks for a fantastic answer and sample code.

-Dave


>From: Bert Freudenberg <bert at freudenbergs.de>
>Reply-To: "A friendly place to get answers to even the most basic 
>questionsabout Squeak." <beginners at lists.squeakfoundation.org>
>To: "A friendly place to get answers to even the most basic questions 
>aboutSqueak." <beginners at lists.squeakfoundation.org>
>Subject: Re: [Newbies] terminate event?
>Date: Sun, 21 Jan 2007 15:48:08 +0100 (MET)
>
>
>Am Jan 21, 2007 um 15:21  schrieb Bert Freudenberg:
>
>>Am Jan 21, 2007 um 14:07  schrieb David Urquhart:
>>
>>>Hi
>>>
>>>I'm a Squeak beginner.  I want to write to the transcript when an  object 
>>>is coming to life and when its terminating.  I have an  initialize method 
>>>for the birth - what is the method called that  fires at death?
>>
>>There is no such method. A message can be send to an object only if  there 
>>is a reference to it. As long as a reference to an object  exists, it is 
>>not dead, it does only get garbage-collected when the  last reference is 
>>removed.
>>
>>About the only thing you can do is to register a *different* object  to be 
>>notified when one object is garbage-collected. This is called  
>>"finalization".
>
>Here's an example. Evaluate this in a workspace:
>
>    x := Object new.
>    x toFinalizeSend: #show: to: Transcript with: 'He''s dead, Jim!\'  withCRs
>
>Nothing should happen. Then do
>
>    x := nil
>
>which should print "was finalized" immediately. This is because x  still 
>holds onto a relatively "new" object, which gets freed very fast.
>
>However, once an object gets "old" it takes until the next full  garbage 
>collection (GC)! Create your object again, but this time, do  this:
>
>    Smalltalk garbageCollect.
>    x := nil.
>
>Nothing will be printed, because the GC reclaims all space, but also  marks 
>all surviving objects as "old". So even though after assigning  nil to x 
>your object is dead, the finalizer does not know it, yet.  Only if you 
>trigger a full GC again, the object's space is reclaimed,  and the 
>finalizer is activated.
>
>- Bert -
>
>
>_______________________________________________
>Beginners mailing list
>Beginners at lists.squeakfoundation.org
>http://lists.squeakfoundation.org/mailman/listinfo/beginners


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




-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.squeakfoundation.org/pipermail/beginners/attachments/20070122/17c982dd/attachment.htm


More information about the Beginners mailing list