Cross-post from druntime: Mixing GC and non-GC in D. (AKA, "don't touch GC-references from DTOR, preferably don't use DTOR at all")
Robert Jacques
sandford at jhu.edu
Thu Dec 16 17:18:52 PST 2010
On Wed, 15 Dec 2010 16:23:24 -0500, Ulrik Mikaelsson
<ulrik.mikaelsson at gmail.com> wrote:
> Cross-posting after request on the druntime list:
> ------------------------------
>
> Hi,
>
> DISCLAIMER: I'm developing for D1/Tango. It is possible these issues
> are already resolved for D2/druntime. If so, I've failed to find any
> information about it, please do tell.
>
> Recently, I've been trying to optimize my application by swapping out
> some resource allocation (file-descriptors for one) to
> reference-counted allocation instead of GC. I've hit some problems.
>
> Problem
> =======
>
> Basically, the core of all my problems is something expressed in
> http://bartoszmilewski.wordpress.com/2009/08/19/the-anatomy-of-reference-counting/
> as "An object’s destructor must not access any garbage-collected
> objects embedded in it.".
[snip]
Having run into this problem with CUDA C language bindings, I do feel your
pain. However, the fact that "An object’s destructor must not access any
garbage-collected objects embedded in it." is a key assumption made by all
GC algorithms (that I know of). Yes, D's current GC only does full
collections, so a child-object knows that it's parent objects are either
valid or are being collected at the same time it is. But this isn't true
for generational collectors, and I wouldn't want D to exclude itself from
a wide range of modern GC.
More information about the Digitalmars-d
mailing list