Signals and Slots in D
Frits van Bommel
fvbommel at REMwOVExCAPSs.nl
Fri Sep 29 11:24:09 PDT 2006
Walter Bright wrote:
> Yes, it is a hack, and an awful one. I think Frits and Thomas have it
> right in suggesting support for a 'weak pointer' that the GC updates for
> moves, but doesn't scan for roots.
Don't forget it should be nulled when the object is deleted[1].
Otherwise you have a pointer that's valid for the lifetime of the object
but dangles around afterwards.
[1] This may be trickier than it seems.
The most only way I can think of that works for deletion by user and by
any GC[2] would probably be to keep track of which weak pointers point
to an object in the object itself.
Java probably has it a bit easier in this regard, since it doesn't have
a 'delete' statement. If you only need to worry about the GC, it's
possible to make sure the GC deletes objects only after scanning
everything while keeping a list of weak pointers found. Though I'm not
sure how Java implementations do this, just guessing here.
[2] Maybe a specific GC can make this easier? I don't know, but I don't
think so. I think 'manual' deletions are probably the hardest to deal with.
More information about the Digitalmars-d
mailing list