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

Stefan Seefeld seefeld at sympatico.ca
Mon Jan 8 23:02:58 CET 2007


Siarhei Rachytski wrote:
> Hi
> 
> I have a python wrapper for a class which implements a Win32 window in
> a separate thread. When it's created the message loop is initiated
> from a separate thread, and when loop exits(this means the user
> pressed the close button and the window should be destroyed), I want
> to delete a C++ object and its python counterpart. I delete C++ object
> using boost::python::decref, however the python variable this object
> has been assigned to still exists, the "print" function shows me smth
> like this (cgepython.Window object at 0xADDRHERE). But I want it to be
> deleted too. How could I implement this behaviour?

Python uses garbage collection to reclaim unreferenced objects (for most
objects that simply means reference counting). Thus, there is no guarantee
that the object will be deleted at a particular point in time.
Some other part of the program may still refer to it, and even if not,
the cleanup may be implemented differently.

Regards,
		Stefan

-- 

      ...ich hab' noch einen Koffer in Berlin...



More information about the Cplusplus-sig mailing list