[PyKDE] qactions not destroyed after qmenu menu closes
apaku at gmx.de
Wed Nov 15 20:16:19 GMT 2006
On 15.11.06 11:28:19, Matt Chambers wrote:
> Andreas Pakulat wrote:
> >On 14.11.06 13:42:29, Matt Chambers wrote:
> >>I'm dynamically creating a context menu for a QTableView, populated with some
> >>QActions. Everytime
> >>I right click, the menu is created. Over time, hundreds of these closed
> >>menus will set in memory, along
> >>with all the qactions, assoctated icons and text, ect. When I close the app,
> >>I see all of them destroyed.
> >>Is there a way to have a qmenu clean up after itself after it closes?
> >Sure, remove all references to it and the python garbage collector will
> >delete it. This means that you shouldn't set the menu as a member of
> >your QTableView subclass but only create it inside the context-menu
> >function as a local instance.
> Maybe I was doing it wrong. I was running menu.popup(). When I switched the
> menu.exec_() everything
> was garbaged collected properly. I didn't make any other changes.
Aah, I was suspecting this. Using menu.popup() runs the popup menu as
another "window" and the function returns immediately. This means that
the function containing the popup call will also end and thus the menu
is garbage collected unless you save a reference to it, for example in a
member variable of self. exec_ runs the menu synchronously and only
returns after the user chose an item.
Don't worry so loud, your roommate can't think.
More information about the PyQt