New submission from Kevin Mills:

The intro paragraph for the gc module's documentation says:

> Since the collector supplements the reference counting already used in 
> Python, you can disable the collector if you are sure your program does not 
> create reference cycles.

How would you ever be sure of that?

While you can prevent reference cycles in your own code, what about your 
dependencies? You'd have to look through the code of all of your dependencies 
and transitive dependencies (including the standard library) to verify that 
none introduce reference cycles. And then you'd have to redo that work when 
upgrading any of them.

I propose adding a function to the gc module that returns True if the gc has 
reclaimed at least one reference cycle in the course of the current program's 
execution.

With that, it would be possible to, a program could, before it exits, force a 
collection and then check if any reference cycles were found over the program's 
lifetime, and then the programmer could use that information to decide whether 
they can safely turn off the gc or not.

Obviously that wouldn't guarantee that you could safely turn of the gc (it's 
possible that garbage with reference cycles is created on other runs of the 
program) it would at least be some information.

----------
messages: 288668
nosy: Kevin Mills
priority: normal
severity: normal
status: open
title: Add function to gc module to check if any reference cycles have been 
reclaimed.
type: enhancement
versions: Python 3.7

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue29671>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to