[issue9141] Allow objects to decide if they can be collected by GC

Kristján Valur Jónsson report at bugs.python.org
Tue Apr 17 12:38:00 CEST 2012


Kristján Valur Jónsson <kristjan at ccpgames.com> added the comment:

I _think_ the only python related things you can do from tp_clear() is Py_DECREF(), this is what I mean by trivial.  This is the reason, for example, that special care was done with generators.
An IO object could of course do non-python operations such as closing files and freeing buffers.

If file.close() can be an arbitrary python method, then it can no more be called from gc, than an object's __del__ method.  This would not be a regression, this would be a fact of life.

The point of _this_ defect (issue 9141) is to allow objects to be smarter about this, being able to tell gc if their finalizers are trivial or not.


I will start a discussion on python-dev to see if anyone knows exactly why these limitations are in place, and what they are.  They are not documented in the source code.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue9141>
_______________________________________


More information about the Python-bugs-list mailing list