On Thu, May 27, 2021 at 8:24 PM Pablo Galindo Salgado
<pablog...@gmail.com> wrote:
> > And if a type pointer is the only thing being visited, then there's no 
> > point unless the object can itself be reachable from the type object.
>
> But that could happen easily for heap types as they are mutable by default. 
> For instance, you set the instance in a global:
>
> type -> module -> globals -> instance -> type

Immutable heap types have the same leak problem. Making a mutable heap
immutable doesn't solve the problem.

Example of my msg385297:

"If one of these conditions is not met, the GC can fail to destroy a
type during a GC collection. If an instance is kept alive late while a
Python interpreter is being deleted, it's possible that the type is
never deleted, which can keep indirectly many objects alive and so
don't delete them neither."

For a more concrete example, read the "_thread lock traverse" section
of my article on these problems:
https://vstinner.github.io/subinterpreter-leaks.html

There were two reference cycles, and both were "connected" with a lock
object in the middle (look at my drawing). The lock object was *not*
directly part of any ref cycle. But because it had no traverse
function, the GC failed to break both cycles in a single collection. A
second manual GC collection was needed to break the second cycles, to
*work around* the issue.

The problem is that a small reference cycle can keep tons of Python
objects alive way longer than expected. If a heap cycle doesn't fully
implement the GC protocol, in the worst case, these objects are never
deleted.

Victor
-- 
Night gathers, and now my watch begins. It shall not end until my death.
_______________________________________________
python-committers mailing list -- python-committers@python.org
To unsubscribe send an email to python-committers-le...@python.org
https://mail.python.org/mailman3/lists/python-committers.python.org/
Message archived at 
https://mail.python.org/archives/list/python-committers@python.org/message/BM55YS7NBNWAHTGEFJS4HSK7UJNRZIDX/
Code of Conduct: https://www.python.org/psf/codeofconduct/

Reply via email to