Is there a weak pointer or references in D?
Era Scarecrow
rtcvb32 at yahoo.com
Fri Jan 11 18:07:25 PST 2013
I had the impression in the original text you wanted to auto
allocate memory when accessing the field, not as described here.
Might be time to re-watch the remainder of the computer science
lectures.
On Friday, 11 January 2013 at 23:51:04 UTC, Nekroze wrote:
> A weak reference to an object is not enough to keep the object
> alive: when the only remaining references to a referent are
> weak references, garbage collection is free to destroy the
> referent and reuse its memory for something else.
How very C++'ish of you. With a weak reference as that, memory
safety becomes a much larger issue (and you likely can only make
@system code, I surely wouldn't mark it @trusted or @safe).
It sorta sounds like what slices are in D; Although D's GC won't
free memory unless it's sure it isn't in use (rather than the
other way around). You might get the desired effect by removing
areas from GC's scanning (for active references), but use at your
own risk.
With that in mind I have the impression you won't find weak
pointers in D (or phobos anyways); Or if they are present, then
it simply lets the object go once the strong pointers are gone
and lets the GC pick it up later (which then weak pointers are
pointless as GC does that anyways).
More information about the Digitalmars-d-learn
mailing list