question about the GC implementation

ryles rylesny at
Sat Oct 3 23:58:39 CEST 2009

On Oct 2, 11:20 am, Francis Moreau <francis.m... at> wrote:
> Hello,
> I'm looking at gcmodule.c and in move_unreachable() function, the code
> assumes that if an object has its gc.gc_refs stuff to 0 then it *may*
> be unreachable.
> How can an object tagged as unreachable could suddenly become
> reachable later ?
> Thanks

It looks like you're not reading through all of the comments:

    move_unreachable() then moves objects not reachable (whether
directly or
    indirectly) from outside the generation into an "unreachable" set.
    Objects that are found to be reachable have gc_refs set to
    again.  Objects that are found to be unreachable have gc_refs set
    GC_TENTATIVELY_UNREACHABLE.  It's "tentatively" because the pass
    this can't be sure until it ends, and GC_TENTATIVELY_UNREACHABLE
    transition back to GC_REACHABLE.

    Only objects with GC_TENTATIVELY_UNREACHABLE still set are
    for collection.  If it's decided not to collect such an object
    it has a __del__ method), its gc_refs is restored to GC_REACHABLE

More information about the Python-list mailing list