[C++-sig] Boost.Python Memory Leaks?

Lawrence Spector Lawrence.Spector at CanfieldSci.com
Thu Jun 28 00:10:04 CEST 2007


I was testing out some of my Boost.Python code using the Boost.Test
framework.  During the running, I got memory leaks reported.  I ran a
simple test to verify, which produced the following output:

 

Running 1 test case...

 

*** No errors detected

Detected memory leaks!

Dumping objects ->

{168} normal block at 0x00366488, 12 bytes long.

 Data: <            > 10 A5 03 10 A0 A5 03 10 00 00 00 00

{166} normal block at 0x003663F8, 12 bytes long.

 Data: <            > C0 A2 03 10 80 A3 03 10 00 00 00 00

{164} normal block at 0x00366368, 12 bytes long.

 Data: <            > D0 84 03 10 00 00 00 00 00 00 00 00

{163} normal block at 0x00366330, 8 bytes long.

 Data: <        > D0 84 03 10 00 00 00 00

{161} normal block at 0x003662A0, 12 bytes long.

 Data: <            > B0 A1 03 10 F0 A1 03 10 00 00 00 00

{159} normal block at 0x00366210, 12 bytes long.

 Data: <            > B0 A0 03 10 F0 A0 03 10 00 00 00 00

{157} normal block at 0x00366180, 12 bytes long.

 Data: <p           > 70 9E 03 10 00 9F 03 10 00 00 00 00

{155} normal block at 0x003660F0, 12 bytes long.

 Data: <`           > 60 9D 03 10 A0 9D 03 10 00 00 00 00

{153} normal block at 0x00366060, 12 bytes long.

 Data: <P           > 50 9C 03 10 90 9C 03 10 00 00 00 00

{151} normal block at 0x00365FD0, 12 bytes long.

 Data: <@   @       > 40 9A 03 10 40 9B 03 10 00 00 00 00

{149} normal block at 0x00365F40, 12 bytes long.

 Data: <            > C0 98 03 10 00 99 03 10 00 00 00 00

{147} normal block at 0x00365EB0, 12 bytes long.

 Data: <            > B0 96 03 10 80 97 03 10 00 00 00 00

{145} normal block at 0x00365E20, 12 bytes long.

 Data: <            > A0 95 03 10 E0 95 03 10 00 00 00 00

{143} normal block at 0x00365D90, 12 bytes long.

 Data: <            > 90 94 03 10 D0 94 03 10 00 00 00 00

{141} normal block at 0x00365D00, 12 bytes long.

 Data: <            > 80 93 03 10 C0 93 03 10 00 00 00 00

{139} normal block at 0x00365C70, 12 bytes long.

 Data: <p           > 70 92 03 10 B0 92 03 10 00 00 00 00

{137} normal block at 0x00365BE0, 12 bytes long.

 Data: <`           > 60 91 03 10 A0 91 03 10 00 00 00 00

{135} normal block at 0x00365B50, 12 bytes long.

 Data: <P           > 50 90 03 10 90 90 03 10 00 00 00 00

{133} normal block at 0x00365AC0, 12 bytes long.

 Data: <            > B0 8E 03 10 80 8F 03 10 00 00 00 00

{131} normal block at 0x00365A30, 12 bytes long.

 Data: <            > 10 8D 03 10 E0 8D 03 10 00 00 00 00

{129} normal block at 0x003659A0, 12 bytes long.

 Data: <            > 90 8B 03 10 20 8C 03 10 00 00 00 00

Object dump complete.

 

 

 

 

The code that produced this is as follows:

 

BOOST_AUTO_TEST_CASE(testPythonDebugIntegration)

{

                {

                                Py_Initialize();

                                {

 

                                                boost::python::object
m_mainModule((boost::python::handle<>(

 
boost::python::borrowed(PyImport_AddModule("__main__")))));

 

                                                boost::python::object
m_mainNamespace(m_mainModule.attr("__dict__"));

                                }

                                Py_Finalize();

                }

}

 

If I change the code to either of the following:

 

1)

 

BOOST_AUTO_TEST_CASE(testPythonDebugIntegration)

{

                {

                                Py_Initialize();

                                {

 

                                                boost::python::object
m_mainModule( (

 
boost::python::borrowed(PyImport_AddModule("__main__"))));

                                }

                                Py_Finalize();

                }

}

 

OR

 

2)

 

BOOST_AUTO_TEST_CASE(testPythonDebugIntegration)

{

                {

                                Py_Initialize();

                                {

                                }

                                Py_Finalize();

                }

}

 

Then I get no memory leaks reported.  Anyone have any clue why this is
happening?  The code I used was basically the suggested code from the
Python tutorial from the Boost.Python page.

 

Thanks in advance,

 

Lawrence

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20070627/aa0e345c/attachment.htm>


More information about the Cplusplus-sig mailing list