Soft/weak references?
Sean Kelly
sean at f4.ca
Thu Jun 21 16:20:32 PDT 2007
BCS wrote:
> Reply to Robert,
>
>> BCS Wrote:
>>
>>> T** ptr;
>>>
>> But this means there's still a reference to it.
>>
>
> It's a total hack. You get a reference to a chunk of memory that
> contains a reference to the data, but you lie to the GC and tell it that
> the chunk of memory doesn't contain any references so it won't notice
> the refernce.
The missing piece is that this reference won't be invalidated if the
object is collected. Phobos has Object.notifyRegister() for this
purpose, but it currently does not exist in Tango because such a
callback could easily deadlock the app if it enters a "synchronized"
block as a part of its processing. In short, I don't know of any
entirely safe means of implementing a weak pointer in D. If someone can
suggest one, I'd be glad to hear it.
Sean
More information about the Digitalmars-d-learn
mailing list