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.
I got into this while cleaning up a mess, but I don't really need the answers to do so. I'm just curious.
Happy New Year everyone!
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.
I got into this while cleaning up a mess, but I don't really need the answers to do so. I'm just curious.
Happy New Year everyone!
Squeak like other Smalltalks only gives you post finalization notification. Other Smalltalks *might* give you pre-notification so that you can act on the object or prevent the object from being finalized.
ObjectMemory>>finalizeReference:
is the location where the object goes away oopGone ifTrue:["Store nil in the pointer and signal the interpreter" self longAt: oop+i put: nilObj. self signalFinalization: oop].
which at some point in the future, usually 5+ milliseconds will run the finalizeValues of the object's class which might for instance call
MPEGFile>>finalize
which contains a bit of trickery to handle the case of mpeg finalization across image saves and restarts. Since you don't have the object at hand to finalize you can of course clone sufficient information about the object perhaps to allow you to do the finalization action with out the object being finalized present.
The usual problem with finalization is that it happens some time in the future, ms to minutes, it can be slow or serialized, it's sometimes fragile, and suddenly finalizing a zillion object might break it. The Squeak finalizer should be reviewed because I'm not sure sufficient care has been taken to prevent broken code from stopping the finalization process from running. If this happens the end results can be a little werid and very hard to debug.
Squeak doesn't support Ephemerons so the order of finalization traversal is undefined. This means of course unlike VisualAge finalization isn't quite such a serialized process, but it might trigger some odd behavior.
http://lists.tunes.org/archives/gclist/2001-October/002263.html
squeak-dev@lists.squeakfoundation.org