[Gc] libgc not collecting objects with cyclic references ?

Bruce Hoult bruce at hoult.org
Mon Mar 19 01:45:02 PST 2007


On 3/19/07, Christophe Meessen <meessen at cppm.in2p3.fr> wrote:
> I am a bit surprized about the statement that cycle references are not
> resolved by the gc. Does this apply only to blocks with clean-up
> functions ? Is the destructor of a C++ function a clean-up function ?

Well what are you going to do?

If A has a pointer to B then it's presumably using B in some way, so
you can't finalize B first because then things in A may crash.  But if
B has a pointer to A then presumably it's using A in some way, so you
can't finalize A first because then things in B might crash.  It's
insoluable.  The GC hasn't got enough information to know what is
safe.

If you know it's safe for B (say) to be alive after A has been
finalized then either:

- B doesn't use A at all during its finalization, in which case make
the pointer from B to A a weak link (disappearing pointer)

- there are some parts of A that B uses and some that it doesn't.
Split A into A and A', make A point to A', and make B point to the
part of A/A' that deosn't have the finalizer.


More information about the Gc mailing list