CPython's cyclic garbage collector (was [Python-ideas] Automatic context managers)
Dave Angel
davea at davea.name
Fri Apr 26 19:48:11 EDT 2013
On 04/26/2013 06:50 PM, Ian Kelly wrote:
> On Fri, Apr 26, 2013 at 10:54 AM, Chris Angelico <rosuav at gmail.com> wrote:
>> Once it's been proven that there's an unreferenced cycle, why not
>> simply dispose of one of the objects, and replace all references to it
>> (probably only one - preferably pick an object with the fewest
>> references) with a special temporary object? In fact, that could
>> probably be done in CPython by wiping out the object in memory and
>> replacing it with a special marker of some sort, which would then
>> automatically "take over" all references to the old object. Any
>> attempt to manipulate this object could simply pop back with a
>> DestructedObject exception or something.
>
> I think it still boils down to the same problem -- how should Python
> *predictably* choose which object will be disposed of in order to
> break the cycle? I don't see that this question is any different than
> asking how should Python choose which __del__ method should be called
> first, since the object so disposed of would still need its __del__
> method called.
>
Perhaps if the __del__ methods disposed of the non-cyclic parts first,
an exception doing the cyclic cleanups wouldn't hurt. Picture a
doubly-linked list of file-type objects. Each one could release its
file before trying to do anything with the links.
--
DaveA
More information about the Python-list
mailing list