[pygtk] PyGObject leaking?
Tony Nelson
tonynelson at georgeanelson.com
Tue Apr 10 13:30:38 WST 2007
At 12:07 AM +0100 4/10/07, Gustavo J. A. M. Carneiro wrote:
>On Seg, 2007-04-09 at 18:49 -0400, Mario Beauchamp wrote:
>[...]
>> 'exiting' is print before my 'dispose' and 'finalize' statements and not
>>after
>> as I expected.
>>
>> I thought that as soon as run() would return, data would go out of
>>scope, its
>> Python ref count would drop to 0, the PyGObject would be freed and
>>release the
>> underlying gobject which would be then disposed and finalized... all this
>> before the 'exiting' line.
>>
>> Am I missing something here? Is my reasonning correct? Or is this a bug?
>
> See http://www.async.com.br/faq/pygtk/index.py?req=show&file=faq08.004.htp
>
>>
>> This is really an important matter for me since the real gv extension
>>module is
>> required by both software packages I am developing (OpenEV and CIETmap). And
>> this is definitely a release stopper...
>
> You should not ever rely on Python objects being freed immediately as
>they go out of scope. Yes, PyGObject exacerbates the problem a bit more
>than it should, but Python itself doesn't guarantee timely garbage
>collection; it just so happens that reference counting ensures garbage
>collection is often right after a reference going out of scope, but not
>always.
Please don't conflate Garbage Collection, a relatively recent addition to
Python, with Reference Counting, Python's basic object reclaimer. Each
provides a way to reclaim (and destroy) unused objects. Reference Counting
does it immediately, while the object may still be in the CPU cache, so it
is fast. Garbage Collection does it later, often much later, and is always
slower than one would expect.
Reference Counting reclaims objects that have no references. If the object
is in a reference loop, only the Cyclic Garbage Collector can reclaim it.
Cyclic garbage can be viewed as an error in the data structure, preventable
by either breaking the cycle manually when the object is expected to become
unreferenced, or by using weak references. (So far I haven't done enough
Python programming to actually make any cyclic references, so I haven't
needed weak refs.)
--
____________________________________________________________________
TonyN.:' <mailto:tonynelson at georgeanelson.com>
' <http://www.georgeanelson.com/>
More information about the pygtk
mailing list