[Qgis-developer] QgsRubberBand RuntimeError: underlying C/C++ object has been deleted

Martin Dobias wonder.sk at gmail.com
Thu Feb 13 05:22:24 PST 2014

On Thu, Feb 13, 2014 at 7:56 PM, Denis Rouzaud <denis.rouzaud at gmail.com> 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.


More information about the Qgis-developer mailing list