On Saturday, 12 January 2013 at 02:49:40 UTC, Jonathan M Davis wrote:

That doesn't fly with the GC, because then you can have a reference to memory that's been freed - though I suppose that it could work if the weak reference
were set to null when the normal reference was collected.

That does fly with GC in languages that are aware of weak pointers. Like OCaml which has a moving GC. From its manual: "A weak pointer is a value that the garbage collector may erase whenever the value is not used any more (through normal pointers) by the program. Note that finalisation functions are run after the weak pointers are erased. A weak pointer is said to be full if it points to a value, empty if the value was erased by the GC."
http://caml.inria.fr/pub/docs/manual-ocaml/libref/Weak.html

So the runtime is aware of weak pointers and clears them to "empty" state when pointed value dies. I don't see yet how it can be implemented in D without patching its GC.

Reply via email to