Alternative Design for Finalisation

Simon Marlow [email protected]
Thu, 20 Sep 2001 13:17:56 +0100


> Unfortunately it isn't possible to add a finalizer to a (Ptr a).  We
> already have a generic finalization mechanism: see the Weak module in
> package lang.  But the only reliable way to use finalizers(*) is to
> attach one to an atomic heap object - that way the compiler's=20
> optimiser
> can't interfere with the lifetime of the object.

I forgot the footnote:

(*) sometimes it doesn't matter that the object being finalized might be
optimised away or duplicated.  For example, we use the notion of
finalizers on arbitrary objects for our implementation of memo tables,
which rely on pointer-equality (actually StableName equality).  If an
object gets optimised away or duplicated by the optimiser, then the memo
table is just less effective.

Cheers,
	Simon