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