This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author andykt
Recipients
Date 2006-03-08.09:46:07
SpamBayes Score
Marked as misclassified
Message-id
In-reply-to
Content
Logged In: YES 
user_id=1281947

> Why do you call Py_Initialize/Py_Finalize more than once?

How else do I tell Python to free up memory after each PyRun_SimpleString
call?

I want users to be able to run scripts many times from within my app.
If I just keep calling PyRun_SimpleString then my app will leak more and
more memory until it becomes unusable.

From http://docs.python.org/api/embedding.html:

  Sometimes, it is desirable to ``uninitialize'' Python. For instance, the
  application may want to start over (make another call to Py_Initialize())
  or the application is simply done with its use of Python and wants to free
  all memory allocated by Python. This can be accomplished by calling
  Py_Finalize().

That's exactly what I want to do.  I want the interpreter to run a script
and then release all the resources used by that script.  Unfortunately,
Py_Finalize does *not* restore memory usage to what it was before the
Py_Initialize call.  I wouldn't mind if there was a one-off allocation
cost (the 1st time Py_Initialize is called), but my app is leaking more
memory *every* time a script is run!
History
Date User Action Args
2007-08-23 14:38:16adminlinkissue1445210 messages
2007-08-23 14:38:16admincreate