[C++-sig] Re: boost: python may cause memory leaks?

Leo Yee surffirst at yahoo.com
Tue Dec 23 13:37:09 CET 2003


If we insert code like this,

     _CrtSetBreakAlloc( 54 );

just after
       _CrtSetDbgFlag ( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF );

we can see where boost::python allocates the memory and I found one of them
was:
    struct py_function
    {
    template <class Caller>
    py_function(Caller const& caller)
        : m_impl(new caller_py_function_impl<Caller>(caller))
    {}
    ...

This is what I saw. If I insert memory leak dectetion code in your way, it
founds nothing.

It is realy confusing.

Leo Yee

"Leo Yee" <surffirst at yahoo.com> дÈëÓʼþ news:bs6tml$r5u$1 at sea.gmane.org...
> Hi, friends,
>
> I use VS 7.1 and I have following code:
>
> #include "stdafx.h"
> #include <crtdbg.h>
>
> using namespace boost::python;
>
> class cPart
> {
> public:
>
>  void set_text( const std::string &t ) { _text = t; }
>  std::string text( void )    { return _text; }
>
> private:
>  std::string _text;
>
> };
>
> BOOST_PYTHON_MODULE(hello)
> {
>
>  class_<cPart, boost::noncopyable >("cPart")
>   .add_property( "text", cPart::text, cPart::set_text );
> }
>
>
> int _tmain(int argc, _TCHAR* argv[])
> {
>     _CrtSetDbgFlag ( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF );
>
>     if (PyImport_AppendInittab("hello", inithello) == -1)
>         return 1;
>
>     Py_Initialize();
>
>  PyRun_SimpleString(
>   "from hello import *\n"
>   "p = cPart()\n"
>   "p.text = 'hello'\n"
>   "print p.text\n"
>   );
>
>     Py_Finalize();
>
>  getchar();
>
>  return 0;
> }
>
> I compiled the code and ran it. Everything was ok except I got memory
leaks
> from the output window of the VS like these:
>
> Detected memory leaks!
> Dumping objects ->
> {54} normal block at 0x003E5AD8, 8 bytes long.
>  Data: < RE   A > 10 52 45 00 83 BE 41 00
> {53} normal block at 0x003E5A90, 8 bytes long.
>  Data: <(RE   A > 28 52 45 00 D6 B6 41 00
> {52} normal block at 0x003E5A48, 8 bytes long.
>  Data: <lRE l A > 6C 52 45 00 6C B2 41 00
> Object dump complete.
>
> I just wonder if I really got memory leaks or it was just a illusion.
> Any suggestion would be appreciated.
>
> Leo Yee







More information about the Cplusplus-sig mailing list