Weak References
Jason House
jason.james.house at gmail.com
Wed Aug 6 17:00:20 PDT 2008
Bill Baxter Wrote:
> On Thu, Aug 7, 2008 at 8:12 AM, Jason House <jason.james.house at gmail.com> wrote:
> > A weak reference library exists but doesn't always work...
>
> By doesn't always work you mean that it seems to you that sometimes it
> prevents the target object from being collected, right?
It causes crashes under the right circumstances. I posted test cases to reproduce the behavior when I was experimenting with it...
>
> But I think you said your only test case for this was something that
> is not reproducible, correct?
>
> Very frustrating to not be able to say for sure. It would be a huge
> help if the GC exposed some API for querying where a particular
> pointer is being referenced. Without that it's really hard to say
> where the reference actually is coming from.
>
> One possible gotcha that just crossed my mind: I think the current GC
> allocates chunks in an all or nothing manner -- hasPointers is just a
> single bit. So could it be that the fact that all Objects have a
> vtable pointer mean that everything in an Object is always treated as
> having pointers?
>
> --bb
>
> > PJP Wrote:
> >
> >> Is there any plan to add support for weak references to the D garbage collector?
> >>
> >> Weak references are references which don't prevent the object from being garbage collected. If it has been garbage collected then the weak reference returns null.
> >>
> >> This is useful for things like resource caches, maintaining references to all instances of a specific class (ex: to implement an operation such as Window.minimizeAllWindows()), or to register a callback/listener with an object such that the registration won't prevent that object from being garbage collected.
More information about the Digitalmars-d
mailing list