Re: python reference leaks

Jack Diederich <[email protected]>
Newsgroups gmane.comp.db.metakit
Message-ID <[email protected]>
On Fri, Apr 15, 2005 at 10:11:18PM -0400, Jack Diederich wrote:
> I've been getting segfaults running metakit in a persistent python interpreter
> (under mod_python, so the interpreter lives for a long time).  I just checked
> out the metakit head (on the server I'm running 2.4.9.3) and jcw figured out
> how to initialize under a python debug build[1] so here is what I can report:
> 
> This is a debug python build so when run interactively it outputs the number 
> of live references after every command.
> 
> The tst.py is just
> import metakit
> import gc
> def round1():
>   def round1():
>   fname = '/tmp/test.mk'
>   stor = metakit.storage(fname, 2)
>   gc.collect() # force cleanup on unreachable objects
>   return
> 
> here is the interactive output, with reference counts.
> 
> Python 2.4.1 (#1, Apr 15 2005, 21:18:43) 
> [GCC 3.3.5 (Debian 1:3.3.5-12)] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
> >>> import tst
> [23817 refs]
> >>> tst.round1()
> [23820 refs]
> >>> tst.round1()
> [23823 refs]
> >>> tst.round1()
> [23826 refs]
> >>> tst.round1()
> [23829 refs]
> 
> So opening a new storage is leaking three refs per go.
> I ran the same test with some python objects I know don't leak (dicts
> and lists) as a sanity test and the #refs after each call stayed static, 
> 
> I'll try and hunt down the leak, but if anyone has any ideas let me know.
> 

Some digging, PyStorage objects are created & destroyed with appropriate
refcounts.  Some of the auxilliary objects created in PyStorage_new leak.

// PyStorage.cpp line 370-ish
  // returning here leaks no refs per call
  PWOString fnm(args[0]);
  // returning here leaks 1 ref per call
  if (PyInt_Check((PyObject* )args[1])) {
    PWONumber mode (args[1]);
    ps = new PyStorage(fnm, mode);
    if (!ps->Strategy().IsValid()) {
  }
  // returning here leaks more (3) refs per call

Closer still ..
_____________________________________________
Metakit mailing list  -  [email protected]
http://www.equi4.com/mailman/listinfo/metakit
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.