[C++-sig] memory leaks when writing Python extension in MSVC6
Andranik Araratyan
Andranik_Araratyan at credence.am
Fri Apr 19 17:16:01 CEST 2002
Hi
I am writing an extension module for Python 2.2.1 with MSVC6.0
, WinNT. I get memory leaks after only importing that module in
Python. This doesn't depend on what you're doing inside the module.
I tried to localize the problem to the following
If we take just the following example module
(the only source file of that module DLL)
===================================
#include "stdafx.h"
#include "Python.h"
static PyObject* ex_foo(PyObject *self, PyObject *args)
{
printf("Hello, world\n");
Py_INCREF(Py_None);
return Py_None;
}
static PyMethodDef example_methods[] =
{
{"foo", ex_foo, 1, "foo() doc string"},
{NULL, NULL}
};
extern"C" void initexample(void)
{
Py_InitModule("example", example_methods);
}
==========================================
and after just calling the Python's "import example" directive (the loading
is successful) and closing it, I got an impressive amount of memory leaks,
which disappear if you just exclude #include "stdafx.h" line from above
text.
Actually, if you even create an empty DLL file from single source file,
containing just that single line #include "stdafx.h" and nothing more, you
get the same memory leaks (of course, with the difference that Python
"import" statement fails in this case).
Is there any way to create an extension module with MFC support not to
produce those memory leaks?
More information about the Cplusplus-sig
mailing list