finalization and garbage collection

Lex Spoon lex at cc.gatech.edu
Wed Jan 2 17:59:23 UTC 2002


John M McIntosh <johnmci at smalltalkconsulting.com> wrote:
> >Is there a method that is guaranteed to be executed just before an 
> >object is garbage collected?
> >I thought #finalize was it, but looking at senders in the image and 
> >ObjectMemory code, it appears that this only gets called when 
> >something that is weakly held gets cleaned up.
> >
> >The weak apparatus seems to use both finalize and the executor 
> >mechanism, and I'm not sure what the roles of these two parts are.
> >


Here's my understanding.

First, only objects that are registered in certain collections will get
finalized.  It's not automatic.  Look up the way, say, sockets arrange
to get finalized, to see how this works.

Second, finalization happens in Squeak *after* the object has been
collected.  Thus, barring fancy magic stuff, a different object must be
used to do the finalization.  That's the "executor", and by default it's
just a shallow copy.  A shallow copy will look just like the original
object, so it's easy to forget that it's not precisely the same object.

This would make a great Swiki page, for someone who really understands
it...

-Lex




More information about the Squeak-dev mailing list