On Fri, Feb 15, 2008 at 2:31 PM, David Matthews David.Matthews@prolingua.co.uk wrote: [...]
It would require the ability to register functions to be called some time after a garbage collection to check the state of the weak references. An alternative would be for the run-time system to broadcast on a global condition variable after each garbage-collection so waking up any threads that needed to check for weak references that had disappeared. Since the post-GC functions would have to run on a separate thread that might actually simplify things.
Finalisation is also a possibility and could probably be written on top of these.
That would be similar to how MLton implements finalizers:
http://mlton.org/cgi-bin/viewsvn.cgi/mlton/trunk/basis-library/mlton/finaliz...
The following post (and the discussion that follows) on MLton's mailing might be useful:
http://mlton.org/pipermail/mlton/2004-September/026127.html
-Vesa Karvonen