[Python-bugs-list] [Bug #110681] memory leak in loops (PR#398)

noreply@sourceforge.net noreply@sourceforge.net
Tue, 3 Oct 2000 13:46:06 -0700


Bug #110681, was updated on 2000-Jul-31 14:14
Here is a current snapshot of the bug.

Project: Python
Category: Core
Status: Closed
Resolution: Fixed
Bug Group: None
Priority: 5
Summary: memory leak in loops (PR#398)

Details: Jitterbug-Id: 398
Submitted-By: ingo.adler@synacon.ch
Date: Fri, 14 Jul 2000 05:10:25 -0400 (EDT)
Version: 1.5.2
OS: win nt


I have a simple loop, which produces memory leaks at every call (36 bytes):

{
    Py_SetProgramName("pythontest.exe");
    Py_Initialize();

    initxmodulec();

    PyRun_SimpleString("print \"... Python started ...\"");

    PyRun_SimpleString("import xmodule");
    PyRun_SimpleString("from xmodule import *");

// The Loop
    PyRun_SimpleString(
        "y = Y()\n"
        "for i in range(1000):\n"
        "\tx = y.getX()\n"
        "\tx.getNumber()\n"
    );




    PyRun_SimpleString("print \"... Python finished ...\"");
    Py_Finalize();
}

X and Y are my classes implemented in C++, connected to Python via Swig Shadow
Classes:

class X {

public:
    float getNumber()
    {
        return 12.2;
    }
};

class Y {
    X* pX;

public:
    Y()
    {
        pX = new X;
    }

    ~Y()
    {
        delete pX;
    }

    X* getX()
    {
        return pX;
    }
};

The classes and python are compiled statically with CBuilder5.0, Swig1.3a3 (same
problem with swig1.1).

I tested the application with "CodeGuard", which shows the memory leaks.
For every call in the loop there is an entry like this (I translated it to
English):

Error. 0x300010 (Thread 0x013B):
resource leak: memory block (0x15422F0) was never released

memory leak (0x015422F0) [size: 36 Byte] was assigned with malloc
call stack:
   0x0045ED5D(=pythontest.exe:0x01:05DD5D)
G:\Projects\src\fortuna\Python\Objects\stringobject.c#145
   0x00401EFD(=pythontest.exe:0x01:000EFD)
G:\Projects\src\fortuna\test\xmodule_wrap.c#769
   0x0040255D(=pythontest.exe:0x01:00155D)
G:\Projects\src\fortuna\test\xmodule_wrap.c#941
   0x0041BA79(=pythontest.exe:0x01:01AA79)
G:\Projects\src\fortuna\Python\Python\ceval.c#2359
   0x0041B912(=pythontest.exe:0x01:01A912)
G:\Projects\src\fortuna\Python\Python\ceval.c#2324
   0x0040EE3E(=pythontest.exe:0x01:00DE3E)
G:\Projects\src\fortuna\Python\Python\bltinmodule.c#12


The Code for line 941:

#define Y_getX(_swigobj)  (_swigobj->getX())
static PyObject *_wrap_Y_getX(PyObject *self, PyObject *args) {
    Y  *_arg0;
    PyObject  *_resultobj,*_argo0=0;
    X  *_result;
    self = self;
    if(!PyArg_ParseTuple(args,"O:Y_getX",&_argo0)) 
        return NULL;
    if ((SWIG_ConvertPtr(_argo0,(void **) &_arg0,SWIGTYPE_Y_p,1)) == -1) return
NULL;
    _result = (X *)Y_getX(_arg0);
/*941*/ _resultobj = SWIG_NewPointerObj((void *) _result, SWIGTYPE_X_p);
    return _resultobj;
}

The Code for line 769:

SWIGSTATICRUNTIME(PyObject *)
SWIG_NewPointerObj(void *ptr, _swig_type_info *type) {
  char result[512];
  PyObject *robj;
  if (!ptr) {
    Py_INCREF(Py_None);
    return Py_None;
  }
#ifdef SWIG_COBJECT_TYPES
  robj = PyCObject_FromVoidPtrAndDesc((void *) ptr, type->name, NULL);
#else
  SWIG_MakePtr(result,ptr,type);
/*769*/  robj = PyString_FromString(result);
#endif
  return robj;
}


Ingo Adler



====================================================================
Audit trail:
Tue Jul 25 07:27:50 2000	guido	changed notes
Tue Jul 25 07:27:50 2000	guido	moved from incoming to open

Follow-Ups:

Date: 2000-Aug-01 14:01
By: none

Comment:
From: "M.-A. Lemburg" <mal@lemburg.com>
Subject: Re: [Python-bugs-list] memory leak in loops (PR#398)
Date: Fri, 14 Jul 2000 11:22:51 +0200

ingo.adler@synacon.ch wrote:
> 
> Full_Name: ingo adler
> Version: 1.5.2
> OS: win nt
> Submission from: megazh-d-201.agrinet.ch (212.28.158.201)
> 
> I have a simple loop, which produces memory leaks at every call (36 bytes):
> 
> {
>     Py_SetProgramName("pythontest.exe");
>     Py_Initialize();
> 
>     initxmodulec();
> 
>     PyRun_SimpleString("print \"... Python started ...\"");
> 
>     PyRun_SimpleString("import xmodule");
>     PyRun_SimpleString("from xmodule import *");
> 
> // The Loop
>     PyRun_SimpleString(
>         "y = Y()\n"
>         "for i in range(1000):\n"
>         "\tx = y.getX()\n"
>         "\tx.getNumber()\n"

Could be that SWIG doesn't get a chance to cleanup the shadow
object for x and y. Try adding

del x,y

as final script line.

Note that SWIG uses Python strings to represent pointers in
C++. It uses an internal table to store these.

>     );
> 
>     PyRun_SimpleString("print \"... Python finished ...\"");
>     Py_Finalize();
> }
> 
> X and Y are my classes implemented in C++, connected to Python via Swig Shadow
> Classes:
> 
> class X {
> 
> public:
>     float getNumber()
>     {
>         return 12.2;
>     }
> };
> 
> class Y {
>     X* pX;
> 
> public:
>     Y()
>     {
>         pX = new X;
>     }
> 
>     ~Y()
>     {
>         delete pX;
>     }
> 
>     X* getX()
>     {
>         return pX;
>     }
> };
> 
> The classes and python are compiled statically with CBuilder5.0, Swig1.3a3 (same
> problem with swig1.1).
> 
> I tested the application with "CodeGuard", which shows the memory leaks.
> For every call in the loop there is an entry like this (I translated it to
> English):
> 
> Error. 0x300010 (Thread 0x013B):
> resource leak: memory block (0x15422F0) was never released
> 
> memory leak (0x015422F0) [size: 36 Byte] was assigned with malloc
> call stack:
>    0x0045ED5D(=pythontest.exe:0x01:05DD5D)
> G:\Projects\src\fortuna\Python\Objects\stringobject.c#145
>    0x00401EFD(=pythontest.exe:0x01:000EFD)
> G:\Projects\src\fortuna\test\xmodule_wrap.c#769
>    0x0040255D(=pythontest.exe:0x01:00155D)
> G:\Projects\src\fortuna\test\xmodule_wrap.c#941
>    0x0041BA79(=pythontest.exe:0x01:01AA79)
> G:\Projects\src\fortuna\Python\Python\ceval.c#2359
>    0x0041B912(=pythontest.exe:0x01:01A912)
> G:\Projects\src\fortuna\Python\Python\ceval.c#2324
>    0x0040EE3E(=pythontest.exe:0x01:00DE3E)
> G:\Projects\src\fortuna\Python\Python\bltinmodule.c#12
> 
> The Code for line 941:
> 
> #define Y_getX(_swigobj)  (_swigobj->getX())
> static PyObject *_wrap_Y_getX(PyObject *self, PyObject *args) {
>     Y  *_arg0;
>     PyObject  *_resultobj,*_argo0=0;
>     X  *_result;
>     self = self;
>     if(!PyArg_ParseTuple(args,"O:Y_getX",&_argo0))
>         return NULL;
>     if ((SWIG_ConvertPtr(_argo0,(void **) &_arg0,SWIGTYPE_Y_p,1)) == -1) return
> NULL;
>     _result = (X *)Y_getX(_arg0);
> /*941*/ _resultobj = SWIG_NewPointerObj((void *) _result, SWIGTYPE_X_p);
>     return _resultobj;
> }
> 
> The Code for line 769:
> 
> SWIGSTATICRUNTIME(PyObject *)
> SWIG_NewPointerObj(void *ptr, _swig_type_info *type) {
>   char result[512];
>   PyObject *robj;
>   if (!ptr) {
>     Py_INCREF(Py_None);
>     return Py_None;
>   }
> #ifdef SWIG_COBJECT_TYPES
>   robj = PyCObject_FromVoidPtrAndDesc((void *) ptr, type->name, NULL);
> #else
>   SWIG_MakePtr(result,ptr,type);
> /*769*/  robj = PyString_FromString(result);
> #endif
>   return robj;
> }
> 
> Ingo Adler
> 
> _______________________________________________
> Python-bugs-list maillist  -  Python-bugs-list@python.org
> http://www.python.org/mailman/listinfo/python-bugs-list

-- 
Marc-Andre Lemburg
______________________________________________________________________
Business:                                      http://www.lemburg.com/
Python Pages:                           http://www.lemburg.com/python/


-------------------------------------------------------

Date: 2000-Aug-01 14:01
By: none

Comment:
From: Ingo Adler <ingo.adler@synacon.ch>
Subject: Re: [Python-bugs-list] memory leak in loops (PR#398)
Date: Fri, 14 Jul 2000 11:40:42 +0100

This is a multi-part message in MIME format.
--------------6D29988B97CCE77010389AE2
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

> > // The Loop
> >     PyRun_SimpleString(
> >         "y = Y()\n"
> >         "for i in range(1000):\n"
> >         "\tx = y.getX()\n"
> >         "\tx.getNumber()\n"
>
> Could be that SWIG doesn't get a chance to cleanup the shadow
> object for x and y. Try adding
>
> del x,y
>
> as final script line.
>
> Note that SWIG uses Python strings to represent pointers in
> C++. It uses an internal table to store these.
>

I changed the code to:

    PyRun_SimpleString(
        "y = Y()\n"
        "for i in range(1000):\n"
        "\tx = y.getX()\n"
        "\tx.getNumber()\n"
        "\tdel x\n"
    );

It doesn't change anything.

The memory leak only occurs when I call x.getNumber() in the loop. Otherwise x =
y.getX() is memory leak free.

Ingo Adler

--------------6D29988B97CCE77010389AE2
Content-Type: text/x-vcard; charset=us-ascii;
 name="ingo.adler.vcf"
Content-Transfer-Encoding: 7bit
Content-Description: Card for Ingo Adler
Content-Disposition: attachment;
 filename="ingo.adler.vcf"

begin:vcard 
n:Adler;Ingo
tel;cell:+41-79-3786792
tel;fax:+41-41-7103244
tel;home:+41-41-7103268
tel;work:+41-41-8111500
x-mozilla-html:FALSE
url:www.synacon.ch
org:Synacon GmbH
adr:;;Rubiswilstrasse 7;Ibach;SZ;6438;Schwitzerland
version:2.1
email;internet:ingo.adler@synacon.ch
title:Dipl.-Inform.
fn:Ingo Adler
end:vcard

--------------6D29988B97CCE77010389AE2--



-------------------------------------------------------

Date: 2000-Aug-01 14:01
By: none

Comment:
From: "M.-A. Lemburg" <mal@lemburg.com>
Subject: Re: [Python-bugs-list] memory leak in loops (PR#398)
Date: Fri, 14 Jul 2000 12:13:13 +0200

Ingo Adler wrote:
> 
> > > // The Loop
> > >     PyRun_SimpleString(
> > >         "y = Y()\n"
> > >         "for i in range(1000):\n"
> > >         "\tx = y.getX()\n"
> > >         "\tx.getNumber()\n"
> >
> > Could be that SWIG doesn't get a chance to cleanup the shadow
> > object for x and y. Try adding
> >
> > del x,y
> >
> > as final script line.
> >
> > Note that SWIG uses Python strings to represent pointers in
> > C++. It uses an internal table to store these.
> >
> 
> I changed the code to:
> 
>     PyRun_SimpleString(
>         "y = Y()\n"
>         "for i in range(1000):\n"
>         "\tx = y.getX()\n"
>         "\tx.getNumber()\n"
>         "\tdel x\n"
>     );
> 
> It doesn't change anything.
> 
> The memory leak only occurs when I call x.getNumber() in the loop. Otherwise x =
> y.getX() is memory leak free.

Two other possibilities:

1. Python interns the string object used by SWIG to represent
the point. It should then free the memory in the Py_Finalize()
call. If it doesn't, there's a bug to be found ;-)

2. SWIG has the leak. Try using the alternative method of
defining SWIG_COBJECT_TYPES (don't know how this is done --
it seems to be new in SWIG).

-- 
Marc-Andre Lemburg
______________________________________________________________________
Business:                                      http://www.lemburg.com/
Python Pages:                           http://www.lemburg.com/python/


-------------------------------------------------------

Date: 2000-Aug-01 14:01
By: none

Comment:
From: Ingo Adler <ingo.adler@synacon.ch>
Subject: Re: [Python-bugs-list] memory leak in loops (PR#398)
Date: Fri, 14 Jul 2000 12:45:02 +0100

This is a multi-part message in MIME format.
--------------82393A6779ADCFC3A2ADE19E
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

I could reproduce the problem with Developer Studio 6.0.

If anyone wants the project to test it - I can provide it.

Ingo Adler

--------------82393A6779ADCFC3A2ADE19E
Content-Type: text/x-vcard; charset=us-ascii;
 name="ingo.adler.vcf"
Content-Transfer-Encoding: 7bit
Content-Description: Card for Ingo Adler
Content-Disposition: attachment;
 filename="ingo.adler.vcf"

begin:vcard 
n:Adler;Ingo
tel;cell:+41-79-3786792
tel;fax:+41-41-7103244
tel;home:+41-41-7103268
tel;work:+41-41-8111500
x-mozilla-html:FALSE
url:www.synacon.ch
org:Synacon GmbH
adr:;;Rubiswilstrasse 7;Ibach;SZ;6438;Schwitzerland
version:2.1
email;internet:ingo.adler@synacon.ch
title:Dipl.-Inform.
fn:Ingo Adler
end:vcard

--------------82393A6779ADCFC3A2ADE19E--



-------------------------------------------------------

Date: 2000-Aug-01 14:01
By: none

Comment:
From: "Mark Hammond" <mhammond@skippinet.com.au>
Subject: RE: [Python-bugs-list] memory leak in loops (PR#398)
Date: Mon, 17 Jul 2000 22:16:54 -0400

> I could reproduce the problem with Developer Studio 6.0.
>
> If anyone wants the project to test it - I can provide it.

If you can repro the problem in just a few lines of C/C++ code but with no
SWIG generated code, I would be interested.  Otherwise, I suggest you do
some more work to narrow the problem down some more; as described, there is
still too much work to be done to narrow down the problem to the cause for
me to be interested (or anyone else given the feedback to date!)

Mark.



-------------------------------------------------------

Date: 2000-Aug-01 14:01
By: none

Comment:
From: Ingo Adler <ingo.adler@synacon.ch>
Subject: Re: [Python-bugs-list] memory leak in loops (PR#398)
Date: Tue, 25 Jul 2000 01:34:22 +0200

This is a multi-part message in MIME format.
--------------72A23DA082087CB843E12C92
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

Hi Mark,

I could repro the memory leaks (they seem to be the same) with a much smaller
program:

int main(int argc, char* argv[])
{
    Py_SetProgramName("pythontest.exe");
    Py_Initialize();
    PyRun_SimpleString("print \"... Python started ...\"");
    PyRun_SimpleString("print \"... Python finished ...\"");
    Py_Finalize();

    return 0;
}

There seems to be a more general problem, which includes my special problem.

Output of Code Guard (translated to English). BoundsChecker shows the same
leaks.

Ingo

Output:

Memory Block (0x014EB9B4) [Size: 37 Byte] was assigned with malloc
Aufrufhierarchie:
   0x0043515A(=pythontest.exe:0x01:03415A)
D:\projects\Python\Objects\stringobject.c#95
   0x0043A8EB(=pythontest.exe:0x01:0398EB)
D:\projects\Python\Python\marshal.c#483
   0x0043A9A1(=pythontest.exe:0x01:0399A1)
D:\projects\Python\Python\marshal.c#504
   0x0043AB88(=pythontest.exe:0x01:039B88)
D:\projects\Python\Python\marshal.c#568
   0x0043AD37(=pythontest.exe:0x01:039D37)
D:\projects\Python\Python\marshal.c#624
   0x0042BC54(=pythontest.exe:0x01:02AC54)
D:\projects\Python\Python\import.c#575

------------------------------------------
Error 00078. 0x300010 (Thread 0x012D):
Resource-Leak: Memory Block (0x14E4858) was never freed

Memory Block (0x014E4858) [Size: 31 Byte] was assigned with malloc
Aufrufhierarchie:
   0x0043526B(=pythontest.exe:0x01:03426B)
D:\projects\Python\Objects\stringobject.c#145
   0x00425400(=pythontest.exe:0x01:024400)
D:\projects\Python\Objects\dictobject.c#1084
   0x00433896(=pythontest.exe:0x01:032896)
D:\projects\Python\Objects\moduleobject.c#56
   0x0042B993(=pythontest.exe:0x01:02A993)
D:\projects\Python\Python\import.c#428
   0x0043B0C9(=pythontest.exe:0x01:03A0C9)
D:\projects\Python\Python\modsupport.c#82
   0x0040C68A(=pythontest.exe:0x01:00B68A)
D:\projects\Python\Python\bltinmodule.c#2393

------------------------------------------
Error 00079. 0x300010 (Thread 0x012D):
Resource-Leak: Memory Block (0x14E47D0) was never freed

Memory Block (0x014E47D0) [Size: 28 Byte] was assigned with malloc
Aufrufhierarchie:
   0x00433CB3(=pythontest.exe:0x01:032CB3)
D:\projects\Python\Objects\object.c#122
   0x00424115(=pythontest.exe:0x01:023115)
D:\projects\Python\Objects\dictobject.c#124
   0x004367D3(=pythontest.exe:0x01:0357D3)
D:\projects\Python\Objects\stringobject.c#1075
   0x00425418(=pythontest.exe:0x01:024418)
D:\projects\Python\Objects\dictobject.c#1087
   0x0043387A(=pythontest.exe:0x01:03287A)
D:\projects\Python\Objects\moduleobject.c#54
   0x0042B993(=pythontest.exe:0x01:02A993)
D:\projects\Python\Python\import.c#428

------------------------------------------
Error 00080. 0x300010 (Thread 0x012D):
Resource-Leak: Memory Block (0x14E47AC) was never freed

Memory Block (0x014E47AC) [Size: 32 Byte] was assigned with malloc
Aufrufhierarchie:
   0x0043526B(=pythontest.exe:0x01:03426B)
D:\projects\Python\Objects\stringobject.c#145
   0x00425400(=pythontest.exe:0x01:024400)
D:\projects\Python\Objects\dictobject.c#1084
   0x0043387A(=pythontest.exe:0x01:03287A)
D:\projects\Python\Objects\moduleobject.c#54
   0x0042B993(=pythontest.exe:0x01:02A993)
D:\projects\Python\Python\import.c#428
   0x0043B0C9(=pythontest.exe:0x01:03A0C9)
D:\projects\Python\Python\modsupport.c#82
   0x0040C68A(=pythontest.exe:0x01:00B68A)
D:\projects\Python\Python\bltinmodule.c#2393

------------------------------------------
Error 00081. 0x300010 (Thread 0x012D):
Resource-Leak: Memory Block (0x14E46E4) was never freed

Memory Block (0x014E46E4) [Size: 35 Byte] was assigned with malloc
Aufrufhierarchie:
   0x0043526B(=pythontest.exe:0x01:03426B)
D:\projects\Python\Objects\stringobject.c#145
   0x004240F7(=pythontest.exe:0x01:0230F7)
D:\projects\Python\Objects\dictobject.c#120
   0x0043C27B(=pythontest.exe:0x01:03B27B)
D:\projects\Python\Python\pythonrun.c#132
   0x00402934(=pythontest.exe:0x01:001934)
G:\Projects\src\test\pythonmain.cpp#15
   0x3257DC12(=CC3250MT.DLL:0x01:07CC12)

------------------------------------------
Error 00082. 0x300010 (Thread 0x012D):
Resource-Leak: Memory Block (0x1524000) was never freed

Memory Block (0x01524000) [Size: 12288 Byte] was assigned with malloc
Aufrufhierarchie:
   0x004243A7(=pythontest.exe:0x01:0233A7)
D:\projects\Python\Objects\dictobject.c#280
   0x004245C4(=pythontest.exe:0x01:0235C4)
D:\projects\Python\Objects\dictobject.c#370
   0x00436837(=pythontest.exe:0x01:035837)
D:\projects\Python\Objects\stringobject.c#1086
   0x00415CA9(=pythontest.exe:0x01:014CA9)
D:\projects\Python\Python\compile.c#249
   0x0043AC12(=pythontest.exe:0x01:039C12)
D:\projects\Python\Python\marshal.c#578
   0x0043A9A1(=pythontest.exe:0x01:0399A1)
D:\projects\Python\Python\marshal.c#504

------------------------------------------
Error 00083. 0x300010 (Thread 0x012D):
Resource-Leak: Memory Block (0x14EFC9C) was never freed

Memory Block (0x014EFC9C) [Size: 35 Byte] was assigned with malloc
Aufrufhierarchie:
   0x0043526B(=pythontest.exe:0x01:03426B)
D:\projects\Python\Objects\stringobject.c#145
   0x0043685E(=pythontest.exe:0x01:03585E)
D:\projects\Python\Objects\stringobject.c#1098
   0x00411EE6(=pythontest.exe:0x01:010EE6)
D:\projects\Python\Objects\classobject.c#126
   0x004118FB(=pythontest.exe:0x01:0108FB)
D:\projects\Python\Python\ceval.c#2720
   0x0040EE08(=pythontest.exe:0x01:00DE08)
D:\projects\Python\Python\ceval.c#1167
   0x0040D597(=pythontest.exe:0x01:00C597)
D:\projects\Python\Python\ceval.c#324

------------------------------------------
Error 00084. 0x300010 (Thread 0x012D):
Resource-Leak: Memory Block (0x14EFC74) was never freed

Memory Block (0x014EFC74) [Size: 35 Byte] was assigned with malloc
Aufrufhierarchie:
   0x0043526B(=pythontest.exe:0x01:03426B)
D:\projects\Python\Objects\stringobject.c#145
   0x0043685E(=pythontest.exe:0x01:03585E)
D:\projects\Python\Objects\stringobject.c#1098
   0x00411ED6(=pythontest.exe:0x01:010ED6)
D:\projects\Python\Objects\classobject.c#125
   0x004118FB(=pythontest.exe:0x01:0108FB)
D:\projects\Python\Python\ceval.c#2720
   0x0040EE08(=pythontest.exe:0x01:00DE08)
D:\projects\Python\Python\ceval.c#1167
   0x0040D597(=pythontest.exe:0x01:00C597)
D:\projects\Python\Python\ceval.c#324

------------------------------------------
Error 00085. 0x300010 (Thread 0x012D):
Resource-Leak: Memory Block (0x14EFC4C) was never freed

Memory Block (0x014EFC4C) [Size: 35 Byte] was assigned with malloc
Aufrufhierarchie:
   0x0043526B(=pythontest.exe:0x01:03426B)
D:\projects\Python\Objects\stringobject.c#145
   0x0043685E(=pythontest.exe:0x01:03585E)
D:\projects\Python\Objects\stringobject.c#1098
   0x00411EC6(=pythontest.exe:0x01:010EC6)
D:\projects\Python\Objects\classobject.c#124
   0x004118FB(=pythontest.exe:0x01:0108FB)
D:\projects\Python\Python\ceval.c#2720
   0x0040EE08(=pythontest.exe:0x01:00DE08)
D:\projects\Python\Python\ceval.c#1167
   0x0040D597(=pythontest.exe:0x01:00C597)
D:\projects\Python\Python\ceval.c#324

------------------------------------------
Error 00086. 0x300010 (Thread 0x012D):
Resource-Leak: Memory Block (0x14F19CC) was never freed

Memory Block (0x014F19CC) [Size: 47 Byte] was assigned with malloc
Aufrufhierarchie:
   0x0043526B(=pythontest.exe:0x01:03426B)
D:\projects\Python\Objects\stringobject.c#145
   0x00431E97(=pythontest.exe:0x01:030E97)
D:\projects\Python\Objects\listobject.c#309
   0x0041137E(=pythontest.exe:0x01:01037E)
D:\projects\Python\Python\ceval.c#2512
   0x0040F906(=pythontest.exe:0x01:00E906)
D:\projects\Python\Python\ceval.c#1503
   0x0040D597(=pythontest.exe:0x01:00C597)
D:\projects\Python\Python\ceval.c#324
   0x0042BAD4(=pythontest.exe:0x01:02AAD4)
D:\projects\Python\Python\import.c#485

------------------------------------------
Error 00087. 0x300010 (Thread 0x012D):
Resource-Leak: Memory Block (0x14F596C) was never freed

Memory Block (0x014F596C) [Size: 32 Byte] was assigned with malloc
Aufrufhierarchie:
   0x0043526B(=pythontest.exe:0x01:03426B)
D:\projects\Python\Objects\stringobject.c#145
   0x0043685E(=pythontest.exe:0x01:03585E)
D:\projects\Python\Objects\stringobject.c#1098
   0x0042CED6(=pythontest.exe:0x01:02BED6)
D:\projects\Python\Python\import.c#1513
   0x0042CD19(=pythontest.exe:0x01:02BD19)
D:\projects\Python\Python\import.c#1441
   0x0042CE6A(=pythontest.exe:0x01:02BE6A)
D:\projects\Python\Python\import.c#1489
   0x00409B32(=pythontest.exe:0x01:008B32)
D:\projects\Python\Python\bltinmodule.c#65

------------------------------------------
Error 00088. 0x300010 (Thread 0x012D):
Resource-Leak: Memory Block (0x14EB870) was never freed

Memory Block (0x014EB870) [Size: 32 Byte] was assigned with malloc
Aufrufhierarchie:
   0x0043515A(=pythontest.exe:0x01:03415A)
D:\projects\Python\Objects\stringobject.c#95
   0x0043A8EB(=pythontest.exe:0x01:0398EB)
D:\projects\Python\Python\marshal.c#483
   0x0043A9A1(=pythontest.exe:0x01:0399A1)
D:\projects\Python\Python\marshal.c#504
   0x0043AB88(=pythontest.exe:0x01:039B88)
D:\projects\Python\Python\marshal.c#568
   0x0043A9A1(=pythontest.exe:0x01:0399A1)
D:\projects\Python\Python\marshal.c#504
   0x0043AB76(=pythontest.exe:0x01:039B76)
D:\projects\Python\Python\marshal.c#567

------------------------------------------
Error 00089. 0x300010 (Thread 0x012D):
Resource-Leak: Memory Block (0x14EFBDC) was never freed

Memory Block (0x014EFBDC) [Size: 34 Byte] was assigned with malloc
Aufrufhierarchie:
   0x0043526B(=pythontest.exe:0x01:03426B)
D:\projects\Python\Objects\stringobject.c#145
   0x0043685E(=pythontest.exe:0x01:03585E)
D:\projects\Python\Objects\stringobject.c#1098
   0x00411C9E(=pythontest.exe:0x01:010C9E)
D:\projects\Python\Objects\classobject.c#58
   0x004118FB(=pythontest.exe:0x01:0108FB)
D:\projects\Python\Python\ceval.c#2720
   0x0040EE08(=pythontest.exe:0x01:00DE08)
D:\projects\Python\Python\ceval.c#1167
   0x0040D597(=pythontest.exe:0x01:00C597)
D:\projects\Python\Python\ceval.c#324

------------------------------------------
Error 00090. 0x300010 (Thread 0x012D):
Resource-Leak: Memory Block (0x14E74C4) was never freed

Memory Block (0x014E74C4) [Size: 988 Byte] was assigned with malloc
Aufrufhierarchie:
   0x00430B62(=pythontest.exe:0x01:02FB62)
D:\projects\Python\Objects\intobject.c#113
   0x00430BFD(=pythontest.exe:0x01:02FBFD)
D:\projects\Python\Objects\intobject.c#163
   0x0040C6FC(=pythontest.exe:0x01:00B6FC)
D:\projects\Python\Python\bltinmodule.c#2404
   0x0043C29A(=pythontest.exe:0x01:03B29A)
D:\projects\Python\Python\pythonrun.c#136
   0x00402934(=pythontest.exe:0x01:001934)
G:\Projects\src\test\pythonmain.cpp#15
   0x3257DC12(=CC3250MT.DLL:0x01:07CC12)

------------------------------------------
Error 00091. 0x300010 (Thread 0x012D):
Resource-Leak: Memory Block (0x14E96C4) was never freed

Memory Block (0x014E96C4) [Size: 174 Byte] was assigned with malloc
Aufrufhierarchie:
   0x0042B0D9(=pythontest.exe:0x01:02A0D9) D:\projects\Python\PC\getpathp.c#403

   0x0042B2D5(=pythontest.exe:0x01:02A2D5) D:\projects\Python\PC\getpathp.c#508

   0x0043E40C(=pythontest.exe:0x01:03D40C)
D:\projects\Python\Python\sysmodule.c#413
   0x0043C2CA(=pythontest.exe:0x01:03B2CA)
D:\projects\Python\Python\pythonrun.c#142
   0x00402934(=pythontest.exe:0x01:001934)
G:\Projects\src\test\pythonmain.cpp#15
   0x3257DC12(=CC3250MT.DLL:0x01:07CC12)

------------------------------------------
Error 00092. 0x300010 (Thread 0x012D):
Resource-Leak: Memory Block (0x14EF660) was never freed

Memory Block (0x014EF660) [Size: 36 Byte] was assigned with malloc
Aufrufhierarchie:
   0x0043526B(=pythontest.exe:0x01:03426B)
D:\projects\Python\Objects\stringobject.c#145
   0x00425400(=pythontest.exe:0x01:024400)
D:\projects\Python\Objects\dictobject.c#1084
   0x0042BA54(=pythontest.exe:0x01:02AA54)
D:\projects\Python\Python\import.c#466
   0x0042BF73(=pythontest.exe:0x01:02AF73)
D:\projects\Python\Python\import.c#724
   0x0042C876(=pythontest.exe:0x01:02B876)
D:\projects\Python\Python\import.c#1202
   0x0042D51E(=pythontest.exe:0x01:02C51E)
D:\projects\Python\Python\import.c#1755

------------------------------------------
Error 00093. 0x300010 (Thread 0x012D):
Resource-Leak: Memory Block (0x15211C8) was never freed

Memory Block (0x015211C8) [Size: 31 Byte] was assigned with malloc
Aufrufhierarchie:
   0x0043526B(=pythontest.exe:0x01:03426B)
D:\projects\Python\Objects\stringobject.c#145
   0x0043685E(=pythontest.exe:0x01:03585E)
D:\projects\Python\Objects\stringobject.c#1098
   0x004129EE(=pythontest.exe:0x01:0119EE)
D:\projects\Python\Objects\classobject.c#517
   0x004246DD(=pythontest.exe:0x01:0236DD)
D:\projects\Python\Objects\dictobject.c#419
   0x0042546E(=pythontest.exe:0x01:02446E)
D:\projects\Python\Objects\dictobject.c#1103
   0x0043DF2E(=pythontest.exe:0x01:03CF2E)
D:\projects\Python\Python\sysmodule.c#95

------------------------------------------
Aufgerufene Funktionen:
 delete (35 Mal)
 getchar (1 Mal)
 fflush (2 Mal)
 fputs (2 Mal)
 fwrite (2 Mal)
 vsprintf (2 Mal)
 strrchr (14 Mal)
 fclose (14 Mal)
 strspn (251 Mal)
 fread (2021 Mal)
 _fgetc (40 Mal)
 fstat (7 Mal)
 fopen (72 Mal)
 strncmp (19 Mal)
 strcmp (423 Mal)
 stat (21 Mal)
 strncpy (32 Mal)
 strchr (125 Mal)
 sprintf (2 Mal)
 memcmp (1349 Mal)
 memset (133 Mal)
 strcpy (834 Mal)
 strlen (784 Mal)
 SysFreeMem (87 Mal)
 SysGetMem (87 Mal)
 realloc (88 Mal)
 memcpy (837 Mal)
 delete[] (2 Mal)
 free (4936 Mal)
 new[] (14 Mal)
 new (40 Mal)
 calloc (5 Mal)
 malloc (4946 Mal)
Verwendete Resource-Arten:
 Datei-Stream (14 Allocs, 5 max)
 Datei-Handle (14 Allocs, 5 max)
 Objekt-Array (14 Allocs, 13 max)
 Objekt (40 Allocs, 28 max)
 Memory Block (5039 Allocs, 2448 max)
Verwendete Module:
 00400000 07/25/2000 01:06:08 G:\Projects\src\bin\pythontest.exe
 0CD00000 02/03/2000 06:00:00 g:\programme\borland\cbuilder5\bin\CG32.DLL
 201A0000 02/22/2000 05:20:00 C:\WINNT.45\TRAYHOOK.dll
 32500000 02/03/2000 06:00:00 G:\Projects\src\bin\CC3250MT.DLL
 40000000 02/03/2000 05:01:00 C:\WINNT.45\System32\VCL50.BPL
 41000000 02/03/2000 06:00:00 G:\Projects\src\bin\BORLNDMM.DLL
 52180000 08/09/1996 00:00:00 C:\WINNT.45\system32\version.dll
 61220000 12/07/1999 16:03:46 G:\Programme\Microsoft
 Hardware\Mouse\MSH_ZWF.dll
 65340000 02/18/2000 16:16:02 C:\WINNT.45\system32\oleaut32.dll
 70970000 05/09/1998 13:57:06 C:\WINNT.45\system32\SHELL32.dll
 70BD0000 03/18/1999 00:00:00 C:\WINNT.45\system32\SHLWAPI.dll
 71190000 07/22/1999 21:09:08 C:\WINNT.45\system32\MSIDLE.DLL
 71590000 03/18/1999 00:00:00 C:\WINNT.45\system32\COMCTL32.dll
 73060000 05/13/1999 12:05:00 C:\WINNT.45\System32\winspool.drv
 77660000 05/13/1999 12:05:00 C:\WINNT.45\System32\MSWSOCK.dll
 77666C35 05/13/1999 12:05:00 C:\WINNT.45\system32\wsock32.dll
 77690000 05/13/1999 12:05:00 C:\WINNT.45\system32\WS2HELP.dll
 776A0000 05/13/1999 12:05:00 C:\WINNT.45\system32\WS2_32.dll
 77710000 05/13/1999 12:05:00 C:\WINNT.45\system32\mpr.dll
 77920000 05/13/1999 12:05:00 C:\WINNT.45\System32\oledlg.dll
 779B0000 08/09/1996 00:00:00 C:\WINNT.45\system32\LZ32.dll
 77B80000 05/13/1999 12:05:00 C:\WINNT.45\system32\ole32.dll
 77D80000 05/13/1999 12:05:00 C:\WINNT.45\system32\comdlg32.dll
 77DC0000 05/13/1999 12:05:00 C:\WINNT.45\system32\ADVAPI32.dll
 77E10000 05/13/1999 12:05:00 C:\WINNT.45\system32\RPCRT4.dll
 77E70000 05/13/1999 12:05:00 C:\WINNT.45\system32\user32.dll
 77ED0000 05/13/1999 12:05:00 C:\WINNT.45\system32\GDI32.dll
 77F00000 05/13/1999 12:05:00 C:\WINNT.45\system32\kernel32.dll
 77F70000 05/13/1999 12:05:00 C:\WINNT.45\System32\ntdll.dll
 78000000 12/07/1999 05:00:00 C:\WINNT.45\system32\MSVCRT.dll
==========================================



Mark Hammond wrote:

> > I could reproduce the problem with Developer Studio 6.0.
> >
> > If anyone wants the project to test it - I can provide it.
>
> If you can repro the problem in just a few lines of C/C++ code but with no
> SWIG generated code, I would be interested.  Otherwise, I suggest you do
> some more work to narrow the problem down some more; as described, there is
> still too much work to be done to narrow down the problem to the cause for
> me to be interested (or anyone else given the feedback to date!)
>
> Mark.

--------------72A23DA082087CB843E12C92
Content-Type: text/x-vcard; charset=us-ascii;
 name="ingo.adler.vcf"
Content-Transfer-Encoding: 7bit
Content-Description: Card for Ingo Adler
Content-Disposition: attachment;
 filename="ingo.adler.vcf"

begin:vcard 
n:Adler;Ingo
tel;fax:+41-41-7103244
tel;work:+41-41-8111500
x-mozilla-html:FALSE
org:Synacon GmbH
adr:;;Rubiswilstrasse 7;Ibach;SZ;6438;Schwitzerland
version:2.1
email;internet:ingo.adler@synacon.ch
fn:Ingo Adler
end:vcard

--------------72A23DA082087CB843E12C92--



-------------------------------------------------------

Date: 2000-Aug-01 14:01
By: none

Comment:
Actually, it's hard to say whether this is worth fixing...
Could it be a SWIG problem?
-------------------------------------------------------

Date: 2000-Sep-25 12:54
By: bwarsaw

Comment:
I don't believe there is a Python bug worth fixing here.  I've done some memory use testing with Python 2.0b2 using Insure++ on Linux, both with the regular interpreter, and with the small example embedded script given below.

There are "technical" memory leaks but they are almost all related to either leaks in the OS, or global memory still in use at the time Python exits.  An example of the former is leaks in strerror() - nothing we can do about that.  An example of the latter are leaks in the string intern dictionary, and we've already decided not to do anything about that.

There no identifiable chunks of memory leaked every time through the loop so I believe the problems reported below are either related to swig, have been fixed for Python 2.0, or are of the variety described above.
-------------------------------------------------------

Date: 2000-Oct-03 07:52
By: tregnago

Comment:
I'm working on an embedded application. I've looked with CodeGuard and it detect few memory leaks( similar as reported below ) only executing "Py_Initialize()" immediatly followed by "Py_Finalize()". Are you sure that this basic example is leaks free in your case?
I'm in big problems with that, and I can't find a way to escape from that.
-------------------------------------------------------

Date: 2000-Oct-03 09:00
By: bwarsaw

Comment:
Re-opening since there really are memory leaks we can fix.
-------------------------------------------------------

Date: 2000-Oct-03 09:35
By: bwarsaw

Comment:
I found a couple of leaks that aren't explained by valid in-reference memory at program exit, or leaks in OS libraries.  Fixes are found in the following files/versions: 

Python/import.c 2.153
Objects/unicodeobject.c 2.65

The last is probably the version that contains the patch.  I haven't actually checked it in yet -- I'm waiting for confirmation from the unicode expert.  I'm still closing this bug report as fixed.

With these patches, all memory leaks now are of the variety described previously.
-------------------------------------------------------

Date: 2000-Oct-03 13:46
By: bwarsaw

Comment:
Just to update, the patch is contained in Objects/unicodeobject.c version 2.66
-------------------------------------------------------

For detailed info, follow this link:
http://sourceforge.net/bugs/?func=detailbug&bug_id=110681&group_id=5470