[C++-sig] Howto delete python object from C++ code.

Grayyoga grayyoga at gmail.com
Tue Jan 9 14:20:04 CET 2007


This is what happens - I create a
boost::python::object(boost::python::ptr(pWindow)), when it goes out
of scope objects references is decremented, becomes 0, interpreter
calls instance_dealloc, which in turn calls boost::python::ptr
destructor... and here it stops - ptr just hold a copy of a pointer,
and doesn't call destructor.

On 1/9/07, Stefan Seefeld <seefeld at sympatico.ca> wrote:
> Siarhei Rachytski wrote:
> > I've just realized what the problem is... The
> > boost::python::object(pWindow) creates a new python object, say py1,
> > and associates the pWindow with it. But somewhere in the interpreter
> > internals live the object py2, which has the same pWindow associated
> > with it. When I delete py1, I also delete pWindow and get a dangling
> > reference held by py2, am I right? If yes, how could I get
> > boost::python::object which represents py2?
>
> Try
>
> boost::python::object(boost::python::ptr(pWindow))
>
> which passes the pointer through, instead of dereferencing it
> to make a copy.
>
> HTH,
>                 Stefan
>
> --
>
>       ...ich hab' noch einen Koffer in Berlin...
> _______________________________________________
> C++-sig mailing list
> C++-sig at python.org
> http://mail.python.org/mailman/listinfo/c++-sig
>



More information about the Cplusplus-sig mailing list