On Sunday, 12 January 2014 at 10:48:15 UTC, Abdulhaq wrote:

No, try this:
import std.stdio;
class X {}
void foo(X x) { writeln(cast(void*) x); }

void main() {
        X x; // null reference by default.
        writeln(cast(void*) x);
        foo(x);

        x = new X;
        writeln(cast(void*) x);
        foo(x);
}

Thanks Tobias that indeed works, unfortunately storing the address as ulong in an AA does not seem to be defeating the garbage collector!

I guess I'll have to go for a WeakRef implementation, I'll try Robert's implementation in signals, but I'd really like to know how long it is likely to last as a working weak ref (in terms of the D GC changing etc.) and if I'm taking the right approach.

The current GC is imprecise. Everything that looks like a pointer at the bit level, is treated like one. I can't help you create weak references.

Reply via email to