[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] PixelArray question



Brian Fisher wrote:

... I do wonder about the question Lenard brought up about whether it
would be bad to trust python's garbage collector to clean up your
objects at the right time. It was my understanding that python always
had ref-counting on, so objects would always be deleted the moment
they went out of scope if they weren't in a cycle, and only then was
it's cleanup time indeterminate.

Aw, yes. For CPython ref-counting is the primary method of garbage collection. And yes, as long as there are not circular references, an object will be immediately collected when its refcount hits zero. There are two areas of concern though. The first is exceptions. A raised exception keeps the stack frames alive until the function that catches it returns. Really not an issue here. The other is that ref-counting is not a language requirement. No assumptions should be made about when an object's deallocator is called. So the __del__ method is considered unreliable. Now ref-counting is totally entrenched in CPython. It will not go away anytime soon. But other versions of Python - Jython, IronPython and PyPy - do not, or may not, use it. So a truly portable Python program cannot rely on ref-counting.

--
Lenard Lindstrom
<len-l@xxxxxxxxx>