[PyQt] Problems freeing objects

Albert Cervera i Areny albert at nan-tic.com
Sat Mar 7 09:13:28 GMT 2009


A Dissabte 07 Març 2009, Andreas Pakulat va escriure:
> 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.

I used 'top', I know it's not a good way of measuring that, but after opening 
and closing a tab 5 or 6 times, memory goes from 60 Mb, then 90 Mb, and up. I 
thought it was clear enough. However, I'll try with valgrind and see what I 
get. Thanks.

>
> Andreas



-- 
Albert Cervera i Areny
http://www.NaN-tic.com


More information about the PyQt mailing list