[PyQt] Problems freeing objects

Andreas Pakulat apaku at gmx.de
Sat Mar 7 00:09:33 GMT 2009


On 07.03.09 00:56:06, Albert Cervera i Areny wrote:
> In my application the main interface is based on tabs. The problem is that 
> when I open a new tab I see memory increase but it does not decrease when I 
> close the tab.
> 
> I've been looking at this and I try to remove the widget from the QTabWidget. 
> Set its parent to None and remove its reference. The code looks like this:
> 
> wid = self.tabWidget.widget(tab)
> self.tabWidget.removeTab( tab )
> wid.setParent( None )
> del wid
> import gc
> gc.collect()
> 
> But that doesn't work. If I print gc.get_referrers( wid ) just before "del 
> wid" I get something like this the list below. 
> There, "Koo.Dialogs.FormWidget.FormWidget" is the widget in the tab (wid), so 
> it seems the only objects referring to the widget are the reference itself 
> (wid) and the methods it has.
> 
> Does anybody know why I don't see memory being freed?

How did you measure that? I suggest to use valgrind to find out wether
you're leaking memory or not. 

Andreas

-- 
You will experience a strong urge to do good; but it will pass.


More information about the PyQt mailing list