question about the GC implementation

F

Francis Moreau

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
 
R

ryles

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:

GC_TENTATIVELY_UNREACHABLE
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
GC_REACHABLE
again. Objects that are found to be unreachable have gc_refs set
to
GC_TENTATIVELY_UNREACHABLE. It's "tentatively" because the pass
doing
this can't be sure until it ends, and GC_TENTATIVELY_UNREACHABLE
may
transition back to GC_REACHABLE.

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

Francis Moreau

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

Ok so it happens _only_ when the object has a __del__ method, right ?

Thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,143
Latest member
DewittMill
Top