[PyKDE] deleting the result of sipMapCppToSelf

David Garcia david at tss-bcn.com
Wed Oct 31 18:49:19 GMT 2001


Thanks for the answers Jim. 

I was playing a little bit with virtual functions in C++ when
I found a curious memory leak (the origin of my question).

My code is something like this:

class AKLeft : public AKBase {...};
...
AKLeft	* nope = new AKLeft();
...
obj = sipMapCppToSelf( nope, sipClass_AKBase );
rslt = PyObject_CallFunction( pcall, "(O)", obj );
Py_XDECREF( rslt );			
Py_XDECREF( obj );
...

Rational Purify doesn't found any leak. Then if I add this code:

obj = sipMapCppToSelf( nope, sipClass_AKLeft );
rslt = PyObject_CallFunction( pcall, "(O)", obj );
Py_XDECREF( rslt );			
Py_XDECREF( obj );

It leaks memory on function sipNew_AKLeft, in the call to sipCreateThis.

Note that I'm using two times the same object nope. Using a new object
for the second sipMapCppToSelf works fine (no leaks). Using in both cases
the same class in the sipMapCppToSelf call (either sipClass_AKBase or
sipClass_AKLeft) produces not leaks too.

Well, I suppose that is not important but is quite curious :)

Best regards,

	David



-----Mensaje original-----
De: pykde-admin at mats.gmd.de [mailto:pykde-admin at mats.gmd.de]En nombre de
Jim Bublitz
Enviado el: miercoles, 31 de octubre de 2001 17:32
Para: pykde at mats.gmd.de
Asunto: [PyKDE] deleting the result of sipMapCppToSelf


On 31-Oct-01 David Garcia wrote:

> I'm using  sipMapCppToSelf to convert a C++ object to a
> PyObject that will be a parameter in a PyObject_CallFunction
> call. My question is, what I should do with the returned 
> PyObject when is no longer needed? Delete it? How? 

   PyObject *obj;

   <do some stuff>

   // Delete it
   Py_DECREF (obj);

(or Py_XDECREF if obj might be NULL)

See the "Python/C API Reference Manual" Py_DECREF is in section 3

Jim

_______________________________________________
PyKDE mailing list    PyKDE at mats.gmd.de
http://mats.gmd.de/mailman/listinfo/pykde




More information about the PyQt mailing list