[python-win32] Memory Leak in MFC/C++ based Python Extended/Embedded code.

Dan Trowbridge dan at thetrowbridgefamily.com
Tue Jan 8 03:07:05 CET 2008


Hi all,

I have a MS Windows/MFC based C++ code that I have implemented Python
embedding/extending in.  (I am using Visual Studio 2003.)  The code seems to
do what I have intended except it always reports a memory leak when it
exits.  I tried all kinds of things but there did not seem to be anything I
could do to get rid of it.

So...

I built a new MFC project and the only things I added was...

	#include <Python.h>

at the top of the application class .cpp file and the following two lines

	Py_Initialize();
	Py_Finalize();

in the application class constructor.

The minimal code STILL reports a memory error.  It looks like the memory
leak had nothing to do with my code.

Anybody have any ideas how to fix this?

Background: I am using Python 2.5.1.  I am not using BOOST::PYTHON (I am
using BOOST::NUMERIC and BOOST::SHARED_PTR for other things in the code -
maybe I should use BOOST::PYTHON - maybe their shared_ptr's would take care
of this for me? ).  I also am not using SWIG or any other "helpers".

Any help would be greatly appreciated.  If this is not the right forum
please advise where to post this.

It got to figure that someone has seen this before - considering as long as
Python has been around and as big as the developer community is.

Thanks in advance for your collective help.

Dannyt






More information about the python-win32 mailing list