Memory leaks

Ingo Adler ingo.adler at synacon.ch
Sun Jul 2 13:15:43 EDT 2000


Hi,

I have some simple Python-Code which generated memory leaks (ca. 4MB):
(The real code is more complicated, but I could strip it down to this
simple example = the smallest example with the memory leak.)
//---------------------------
x = X()

for i in range(100000):
    y = x.getY()
    y.getNumber()
//---------------------------

It doesn't generate memory leaks when:

//---------------------------
x = X()

y = x.getY()
for i in range(100000):
    y.getNumber()
//---------------------------

or

//---------------------------
x = X()

for i in range(100000):
    y = x.getY()
//---------------------------

So getY and getNumber don't generate memory leaks on their own.

Details:

X and Y are implemented in C++ and connected to python via Swig-Shadow
classes.

The Implementation of  X:

class X {
    Y* pY;
public:
    X() {
        pY = new Y;
    }

    ~X() {
        delete pY;
    }

    Y* getY() {
        return pY;
    }
};

The Implementation of Y:

class Y {
    float getNumber() {
        return 3.4;
    }
};

The wrapper code it generated straight forward - nothing special,
nothing hidden.

I use Python 1.5.2, Borland C++ Builder 5.0 with statically linked
Python. My code is much bigger and works pretty well - except the memory
leaks. So the basic integration works.

I hope someone has a solution!

Ingo
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ingo.adler.vcf
Type: text/x-vcard
Size: 338 bytes
Desc: Card for Ingo Adler
URL: <http://mail.python.org/pipermail/python-list/attachments/20000702/807a33a5/attachment.vcf>


More information about the Python-list mailing list