Bug? GC collects memory that references itself.

Rainer Deyke rainerd at eldwood.com
Mon Oct 26 20:30:00 PDT 2009

Jeremie Pelletier wrote:
> I need objects that may live without any references in GC memory, this
> is for bindings to a C++ library. Using ranges or roots would be very
> inneficient so my solution was to have the objects reference themselves
> until the C++ side of the object calls a finalizer which nullify the
> reference to let the GC collect the memory.

That's a (degenerate) reference cycle.  Collection of reference cycles
is not only intentional, but one of the main reasons for using GC in the
first place.

So, don't do that.  It doesn't work, it will never work, and
fundamentally it /can't/ work and /shouldn't/ work.

Rainer Deyke - rainerd at eldwood.com

More information about the Digitalmars-d-learn mailing list