On 27.05.2021 20:20, Pablo Galindo Salgado 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
Modules dicts are cleared during interpreter shutdown to break
such cycles. You would not really want to use GC to clear
type objects: if you GC the type object before the instance,
this would create really difficult to handle situations :-)
Also: Why are types mutable ? AFAIK, they are only meant to be
mutable at C level and then only until they are fully initialized
(PyType_Ready() called).
> On Thu, 27 May 2021, 19:07 Tim Peters, <tim.peters@gmail.com
> <mailto:tim.peters@gmail.com>> wrote:
>
> [Tim Peters <tim.peters@gmail.com <mailto:tim.peters@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.
>
--
Marc-Andre Lemburg
eGenix.com
Professional Python Services directly from the Experts (#1, May 27 2021)
>>> Python Projects, Coaching and Support ... https://www.egenix.com/
>>> Python Product Development ... https://consulting.egenix.com/
________________________________________________________________________
::: We implement business ideas - efficiently in both time and costs :::
eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48
D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg
Registered at Amtsgericht Duesseldorf: HRB 46611
https://www.egenix.com/company/contact/
https://www.malemburg.com/