Weak references.
Bill Baxter
dnewsgroup at billbaxter.com
Sun Apr 13 18:30:22 PDT 2008
Jason House wrote:
> Jarrett Billingsley wrote:
>
>> "Jarrett Billingsley" <kb3ctd2 at yahoo.com> wrote in message
>> news:fttdej$1nfs$1 at digitalmars.com...
>>> "Sean Kelly" <sean at invisibleduck.org> wrote in message
>>> news:fttd02$1mp1$1 at digitalmars.com...
>>>> Are these tables AAs? And how do the weak references store their
>>>> reference?
>>>> The type information provided to AAs is a bit weak, and so some
>>>> non-pointer
>>>> data is currently still scanned by the GC. I'm going to improve this a
>>>> bit in the
>>>> next Tango release, but it still won't be perfect (because the compiler
>>>> doesn't
>>>> provide enough info for it to be).
>>> In my tests I've just been doing
>>>
>>> auto weakref = new WeakRef!(A)(new A);
>>>
>>> and then checking that after doing god-knows-what to try to get it to
>>> collect that instance of A, so it's not even that I'm doing anything that
>>> crazy.
>>>
>> Testing my code in Linux causes a crash in glibc's free() after the
>> program
>> exits. (And the assertion still fails.)
>>
>> Something really weird is happening.
>
> Ok, my latest testing (and testing by others for configurations I don't
> have) are collected in the list below. I don't see any pattern.
>
> tango+linux+dmd = works
> tango+linux+gdc = crash in glibc
> tango+windows+dmd = does not collect
> tango+windows+gdc = ???
> phobos+linux+dmd = works
> phobos+linux+gdc = does not collect
> phobos+windows+dmd = ???
> phobos+windows+gdc = ???
>
> These tests are based off the code at http://tango.pastebin.com/m10aa57b6
> Note that phobos users must comment out the version=Tango line. Any
> additional tests would be appreciated.
>
I'd be worried about stack references in the second example. That inner
function makeWa may be getting inlined or something with some compiler
combos.
The first unittest there works ok right? Maybe explicitly overwriting a
with null after using it would help.
Anyway, I'm pretty sure Sean said after he added the functions to Tango
that he thought they should work but they weren't tested very well. So
I wouldn't be surprised if there were issues. And really, Phobos's gc
functions for weak ref support probably haven't been tested all that
well either.
--bb
More information about the Digitalmars-d
mailing list