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

Kristján Valur Jónsson report at bugs.python.org
Tue Jul 20 23:03:46 CEST 2010


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

I agree that this is not the _optimal_ solution, and that when you are collecting stuff, say a list of many items, it will cause X indirect calls to all of the things in the list.

My counterargument is, however, that all those items will, if collected, be handed off to the final Py_DECREF with all the baggage that that entails, ultimately resulting in PyObject_Free or PyMem_Free.  An extra indirect call, (only for unreachable objects, btw, which is only a small objects of all objects visited during a GC pass) should not play a significatn part in the process.

An alternative to this extra tp_traverse() pass, would be to flag objects that report that they are or are not collectable, with a special  value in gc_refs, probably a bitmask.  But this would be a much more intrusive change in an algorithm that is far from simple, and so need very rigorous review and testing.

----------

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


More information about the Python-bugs-list mailing list