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