[PyKDE] Memory leak when overriding QListViewItem.key()?
Fredrik Juhlin
laz at strakt.com
Mon Aug 19 09:38:00 BST 2002
On Sat, 2002-08-17 at 15:12, Phil Thompson wrote:
> Fredrik Juhlin wrote:
>
> > Hi!
> >
> > While trying to figure out the best way to control the sorting of a
> > QListView, I stumbled over what seems to be some sort of memory leak
> > when I override QlistViewItem.key().
> >
> > When I run the code below, my python process uses aprox 58MB. If I
> > uncomment the key() method in MyListItem, it uses 150MB.
> >
> > If there's a reasonable explanation for this that eludes me, or if I'm
> > simply doing something horribly wrong, please let me know :)
>
> What about MyListItem.__init__()?
Just overriding __init__() does not cause any difference in memory
consumption.
I tried a few others, with the following result:
text(): Increased memory usage (Seemingly identical to overriding key())
compare(): No increase in memory usage
//Fredrik Juhlin
#!/usr/bin/env python
import qt
import sys
class MyListItem(qt.QListViewItem):
def __init__(self, parent):
qt.QListViewItem.__init__(self, parent)
# NOTE: Uncomment either of the methods below for memory-eating
# behaviour
# def key(self, column, ascending):
# return qt.QListViewItem.key(self, column, ascending)
# def text(self, column):
# return qt.QListViewItem.text(self, column)
if __name__ == '__main__':
app = qt.QApplication(sys.argv)
lw = qt.QListView()
lw.addColumn('Mepp')
for x in xrange(5000):
li = MyListItem(lw)
li.setText(0, str(x))
app.setMainWidget(lw)
lw.show()
app.exec_loop()
More information about the PyQt
mailing list