This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: gc.collect() won't always collect as expected
Type: behavior Stage: test needed
Components: Versions: Python 3.2, Python 3.3, Python 2.7
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: loewis, pitrou
Priority: normal Keywords:

Created on 2009-01-12 13:03 by pitrou, last changed 2022-04-11 14:56 by admin.

Messages (2)
msg79673 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2009-01-12 13:03
I haven't verified this through any test (actually I'm wondering how to
deterministically reproduce it), but logically there are cases where
gc.collect() (and, similarly, PyGC_Collect()) won't work as advertised.

Specifically, when the GC is asked to collect a given generation but a
younger generation is already being collected, collect() will simply
notice this and return 0. However, only the younger generation will have
been collected, not the generation asked by the user.

It wouldn't take too much effort to make gc.collect() and PyGC_Collect()
truely deterministic.
msg79674 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2009-01-12 13:22
It should be possible to trigger this by invoking gc.collect in an
__del__ implementation of an object that is attached to a cycle.

However, I don't think this is an important issue; +0 for resolving this
by documenting the status quo (instead of making the implementation
match the documentation).
History
Date User Action Args
2022-04-11 14:56:44adminsetgithub: 49174
2011-06-26 19:01:19terry.reedysetversions: - Python 2.6
2011-06-26 19:01:06terry.reedysetversions: + Python 3.2, Python 3.3, - Python 3.0, Python 3.1
2009-01-12 13:22:33loewissetnosy: + loewis
messages: + msg79674
2009-01-12 13:03:33pitroucreate