Bugs item #1445210, was opened at 2006-03-08 10:20
Message generated for change (Tracker Item Submitted) made by Item Submitter
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1445210&group_id=5470

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: Python Interpreter Core
Group: None
Status: Open
Resolution: None
Priority: 5
Submitted By: Andrew Trevorrow (andykt)
Assigned to: Nobody/Anonymous (nobody)
Summary: embedding Python causes memory leaks

Initial Comment:
[This bug has been submitted by others but for some reason it
has been marked Closed.  I consider it to be an extremely serious
bug -- if I can't solve it I'm going to have to abandon Python as
my app's scripting language, even though I've fallen in love!]

I've added Python script support to my cross-platfom wxWidgets app
so that users can run .py scripts from within the app to automate the
GUI and do other fancy things.  It all works very nicely, except for
one nasty problem: *every* time a script is run there is a memory leak,
usually small (about 10K) but sometimes massive (about 4MB in the 
case of one rather complicated script).

The problem occurs on both Mac OS 10.3.9 and Windows 2000.
I'm using Python 2.3 on the Mac and 2.4.2 on Windows.

Every time the user runs a script, my app makes these calls:
(I've removed a lot of irrelevant stuff.)

   Py_Initialize();
   PyRun_SimpleString("execfile('foo.py')");
   Py_Finalize();

It's definitely not a wxWidgets problem.  In fact it's quite easy to
see the memory leak using a simple command-line program:

#include <stdio.h>
#include <Python.h>
main(int argc, char *argv[])
{
   int i;
   for (i=0; i<1000; i++) {
      Py_Initialize();
      Py_Finalize();
      printf(".");
      if ((i+1) % 50 == 0) printf("\n");
   }
}

Note that it doesn't even execute a script.  If I run this program on
my Mac and watch its memory usage with Activity Monitor, I see a leak
of about 10K each time through the loop.  Similar result on Windows.

Curiously, on both machines, the Py_Finalize() call takes longer and
longer to complete whatever it's doing.  The above program takes a
few *minutes* to complete on my 400MHz Mac.

Andrew


----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1445210&group_id=5470
_______________________________________________
Python-bugs-list mailing list 
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to