On Thu, Feb 13, 2014 at 7:56 PM, Denis Rouzaud <[email protected]> wrote: >> >> 2) If a SIP wrapper class A has a member class B and an instance of A >> is created in Python, B member is referenced and reference to A is >> deleted is it the A instance deleted by GC including B (which is still >> referenced)? >> >> C++: class A { B b; } >> SIP: class A { B b; } >> Python: >> a = A() >> b = a.b >> a = None >> # garbage collector >> >> a and b were deleted? > > I would say yes too. But, I would ask confirmation to people more aware than > me. There should be some reading this ;)
My understanding is following: with the line "a = None" the reference count to SIP wrapper of A gets to zero. Because the object is owned by Python (it was created in Python and the ownership was not transferred to c++), also the underlying C++ object will be deleted. As far as I know, "b" will still reference to SIP wrapper of B which in turn references C++ object that has been deleted in the meanwhile. Using "b" will may lead to crashes (or just strange behavior). If the class "B" had a virtual destructor, the SIP wrapper for B (which is subclass of B) should be at least be notified that the instance is going to be deleted - so when trying to use "b" again, SIP can at least raise the exception instead of crashing. The above is my expectation of what happens, I have not actually tried that. Martin _______________________________________________ Qgis-developer mailing list [email protected] http://lists.osgeo.org/mailman/listinfo/qgis-developer
