>>>>>> On Mon, 14 Mar 2005 15:34:04 -0000 (GMT), "Phil Thompson" >>>>>> <[EMAIL PROTECTED]> said: > >>>>>>>> On Thu, 3 Mar 2005 09:17:07 -0000 (GMT), "Phil Thompson" >>>>>>>> <[EMAIL PROTECTED]> said: >>> Enabling tracing with SIP, I get the following when I call the >>> clone() member function in C++... >>> >>> FunctionBase * sipFunctionBase::clone() const (this=0x083b0878) >>> python.clone >>> sipFunctionBase::sipFunctionBase(const FunctionBase&) (this=0x0842b2d8) >>> python.copy >>> sipFunctionBase::~sipFunctionBase() (this=0x0842b2d8) > >> This isn't very helpful unless it shows your Python debug print >> statements so that you can see the exact order that things are >> happening. > > The Python print statements are prefixed by `python.'
Whoops - missed that. >> Obviously it will do this if you aren't saving the result of the >> call to clone(). > > I'm trying to save the results to clone() in C++. You mean you are not saving a reference to the Python object returned by clone()? If you are not saving a reference then it will immediately get garbage collected and, because the underlying C++ instance is owned by Python then it's dtor will be called. You must either keep a reference or transfer ownership to C++ using sip.transfer() - and make sure you call the C++ dtor explicitly at some stage to avoid a memory leak. >>> What might I try next? > >> Additional debug statements to see exactly which Python statement >> the dtor is being called from. > > As far as I can see, from the above... > > - C++ calls virtual function clone() of the base class (FunctionBase) > - sipFunctionBase get called, it calls clone() of the Python function. > - clone of the Python function calls the "copy constructor". > - sipFunctionBase copy constructor gets called and it calls Python > function's __init__ with two arguments > - Python __init__ prints "python.copy". > - sipFunctionBase destructor gets called, destroying the newly > constructed object. What you haven't shown is the Python code that calls clone(). Phil _______________________________________________ PyKDE mailing list [email protected] http://mats.imk.fraunhofer.de/mailman/listinfo/pykde
