[PySide] Is del in python completely equivalent to delete in c for Qt objects?

John Ehresman jpe at wingware.com
Thu Feb 6 22:00:15 CET 2020


On 2/7/20 9:41 AM, Israel Brewster wrote:
> On Feb 6, 2020, at 11:28 AM, John Ehresman <jpe at wingware.com 
> <mailto:jpe at wingware.com>> wrote:
>>
>> In general, del in Python is very different than delete in C++.  I'll 
>> leave it to others to explain. 
> 
> In general, sure. In general, python memory management is very different 
> than C/C++ memory management, so it stands to reason that del/delete 
> would, in general, be different as well. I’m not asking about the 
> general case, I’m asking about the Qt case, and the things that Qt does 
> when you delete a Qt object. I’m not asking for a low-level view of 
> memory management. I’m asking if the *behavior*, as far as *Qt* objects 
> is concerned, is the same.

With PyQt or PySide, C++ delete is called when the last Python reference 
is dropped to an object created from Python (there are other conditions 
as well).  Python del will drop a reference to the object so C++ delete 
will be invoked if there are no other references to the object (and 
other conditions are met).  In my experience, relying on this is a 
mistake because there are often other references in all but the simplest 
examples.
>> or PySide may expose a function to do a C++ delete -- it's probably 
>> shiboken.delete().
> 
> That sounds like what I’m looking for, assuming that a python del 
> doesn’t do the same thing.

If you want to be sure C++ delete is called, I recommend that you use 
the function to call it.

John


More information about the PySide mailing list