Mark S. Miller (2013-11-06T19:02:36.000Z)
forbes at lindesay.co.uk (2013-11-07T12:53:10.382Z)
In a garbage collected language, this is known as pre-mortem finalization, as in Java's finalize method and finalizer queue, and it is an unmitigated disaster. It is like shared state multi-threading in that it creates a category of bugs -- in this case, resurrection bugs -- that you totally underestimate until you get bitten by them over and over, in code you thought you had carefully thought through. The problem is that, upon invoking the finalize method of the condemned object, the object is *no longer* garbage because it is running. Since non-garbage is reachable from garbage, the condemned object can make state changes to non-condemned state, including storing a pointer back to itself **or other co-condemned objects**, "resurrecting" them in that they are now non-garbage. Post-mortem finalization by various Smalltalk folks was a major innovation. Its central insight is that computation never touches condemned state, and so you never need worry about the possibility of resurrection. I have found that anything useful that could be expressed with pre-mortem finalization can be expressed, usually better, with post-mortem finalization by a bit of refactoring.