Comment 3 for bug 316722

Revision history for this message
A.G. Nienhuis (a-g-nienhuis) wrote : Re: [Bug 316722] Re: python-poppler doesn't close files

I did investigate further and did some testing:

Current release:

- all python objects get destroyed automatically
- files stay open
- memory leak per document_new_from_file(): 40 kB (for a 300 kB pdf file)
- gc.collect() does nothing

If you call g_object_unref(hash(doc)) after each call to
document_new_from_file() the problems go away:

- all python objects get destroyed automatically
- files are closed
- memory leak per document_new_from_file(): 70 bytes (for a 300 kB pdf file)
- gc.collect() does nothing
- doc is completely usable after g_object_unref(...)

BTW: hash(obj) returns the pointer to the gobject of a PyGobject.

Here is a simple test case:

=================================
import os
import poppler
from ctypes import *

glib = CDLL("libgobject-2.0.so")

uri = "file://" + os.path.abspath("test.pdf")
for i in xrange(1000000):
    print i
    doc = poppler.document_new_from_file(uri, None)
    glib.g_object_unref(hash(doc))
====================================

On Fri, Apr 10, 2009 at 11:23 PM, Gian Mario Tagliaretti
<email address hidden> wrote:
>
> I've looking into this one for a long time with no real solution but I
> feel the GC could be the one to blame, did you investigate further?