Antoine Pitrou added the comment:
> It appears that a few (1-3) module dicts are not being purged because they
> have been "orphaned". (i.e. the module object was garbaged collected before
> we check the weakref, but the module dict survived.)
Module globals can be kept alive by any function defined in that module. So if
that function is registered eternally in a C static variable, the globals dict
will never get collected.
> ./python -v -Xshowrefcount check_purging.py
I always get either:
# remaining {'encodings', '__main__'}
[...]
[24834 refs, 7249 blocks]
or
# remaining {'__main__', 'encodings'}
[...]
[24834 refs, 7249 blocks]
... which seems to hint that it is quite stable actually.
The encodings globals are kept alive because of the codecs registration, I
believe.
As for the __main__ dict, perhaps we're missing a decref somewhere.
> Maybe 8 out of 50+ module dicts actually die a natural death by being
> garbage collected before they are purged.
I get different numbers from you. If I run "./python -v -c pass", most modules
in the "wiping" phase are C extension modules, which is expected. Pretty much
every pure Python module ends up garbage collected before that.
By the way, please also try issue18608 which will bring an other improvement.
----------
_______________________________________
Python tracker <[email protected]>
<http://bugs.python.org/issue18214>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com