> 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

On Thu, 27 May 2021, 19:07 Tim Peters, <tim.pet...@gmail.com> wrote:

> [Tim Peters <tim.pet...@gmail.com>]
> > ...
> > This is, I believe, akin to what Marc-Andre is bringing up:  if X
> > can't be reached _from_ X's type object, there's no need for X's
> > tp_traverse to visit X's type object.  It _can_ be visited, but it
> > would be a waste of time.
>
> Ya, I need to retract that :-)  If X's type object is in a cycle not
> directly containing X, and X is in a cycle not directly containing its
> type object, and both cycles are dead, then X's tp_traverse must visit
> X's type object for cyclic gc to deduce that the cycle directly
> containing the type object _is_ dead.
>
> Else only the cycle containing X will be reclaimed, and the cycle
> containing the type object will have to wait for another gc run.
>
> But that doesn't apply to some of the patches we're seeing. We're
> seeing visits to things that can't possibly be parts of cycles:
>
> +static int
> +pattern_traverse(PatternObject *self, visitproc visit, void *arg)
> +{
> +    Py_VISIT(Py_TYPE(self));
> +    Py_VISIT(self->groupindex);
> +    Py_VISIT(self->indexgroup);
> +    Py_VISIT(self->pattern);
> +    return 0;
> +}
> +
>
> For example, self->pattern there is a string.  For that matter, it's
> hard to conceive of how a regexp pattern object could possibly be a
> direct member of any cycle.
>
> 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.
>
_______________________________________________
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/TO4SD5USMVM5JJ636Q7VGA4PBZ5EJA42/
Code of Conduct: https://www.python.org/psf/codeofconduct/

Reply via email to