weak references

PJP pete.poulos at gmail.com
Wed Aug 6 05:13:47 PDT 2008


I don't think this solution is safe.  According to (http://www.digitalmars.com/d/2.0/garbage.html), this is undefined behavior, "Do not store pointers into non-pointer variables using casts and other tricks. "  and "Do not store into pointers values that may point into the garbage collected heap...A copying garbage collector may change this value"

PJP

Bill Baxter Wrote:

> It provides a call-back hook that can be set to get a notification
> when an object you're interested in is destroyed.
> And in general size_t's and other integer types are not treated as pointers.
> 
> These two things can be used to make a weak ref class, which is what
> has been done here:
> 
> http://www.dsource.org/projects/scrapple/browser/trunk/weakref
> 
> On Wed, Aug 6, 2008 at 2:06 PM, PJP <pete.poulos at gmail.com> wrote:
> >
> > Does the D garbage collector provide something similar to the "weak" references in Java?  Weak references don't prevent the object they refer to from being garbage collected.  If the object has been garbage collected, the weak reference will return null.
> >



More information about the Digitalmars-d-learn mailing list