Package: python-qt3
Version: 3.13-4
Severity: normal
I have an application prototype made with PyQT, it seems to leak lots
of memory with no reason. After two or three hours of normal usage,
the machine hangs with their 256mb of ram exhausted, swaping to
death. I tried to isolate the bug, I think is present in the QDialog
creation, maybe in more places too. Here is a test script with
their sample output, press Enter many times and see how the memory
grows and grows by pressing 'M':
#--------------------------------------------------------------------
#!/usr/bin/python
import os, sys, time, gc
from qt import *
### Query Memory Usage Functions
_proc_status = '/proc/%d/status' % os.getpid()
_scale = {'kB': 1024.0, 'mB': 1024.0*1024.0,
'KB': 1024.0, 'MB': 1024.0*1024.0}
def _VmB(VmKey):
global _proc_status, _scale
VmKey = "Vm"+VmKey+":"
# get pseudo file /proc/<pid>/status
try:
t = open(_proc_status)
v = t.read()
t.close()
except:
return 0.0 # non-Linux?
# get VmKey line e.g. 'VmRSS: 9999 kB\n ...'
i = v.index(VmKey)
v = v[i:].split(None, 3) # whitespace
if len(v) < 3:
return 0.0 # invalid format?
# convert Vm value to bytes
return float(v[1]) * _scale[v[2]]
mem_types = ('RSS', 'Stk', 'Data', 'Lib', 'Size')
def memoryUsage():
return "Current Memory Usage: " + " ".join(["%s:%s" % (k, _VmB(k)) for k in
mem_types])
max_mem_by_type = {}
for t in mem_types:
max_mem_by_type[t] = _VmB(t)
def check_leak(s):
for mem_type, value in max_mem_by_type.items():
current_mem = _VmB(mem_type)
if current_mem > value:
print "\tAT %s: MAX '%s' MEMORY INCREASED FROM %d TO %d (+%d)" % \
(s, mem_type, value, current_mem, current_mem-value)
sys.stdout.flush()
max_mem_by_type[mem_type] = current_mem
###
class LeakDialog(QDialog):
def __init__(self,parent = None,name = None,modal = 0,fl = 0):
QDialog.__init__(self,parent,name,modal,fl)
class Main(QMainWindow):
def __init__(self):
QMainWindow.__init__(self)
def keyPressEvent(self, event):
NUM_FORMS = 10000
k = event.key()
if k in (QKeyEvent.Key_Enter, QKeyEvent.Key_Return):
print "*** Creating %d LeakDialog's" % NUM_FORMS
check_leak("Pre-Creating")
for x in range(NUM_FORMS):
f = LeakDialog()
f = None
print "End Creating"
print "Forcing GC"
col = gc.collect()
uncol = len(gc.garbage)
if col or uncol:
print "GC Collected: %d Uncollected: %d" % (col, uncol)
print "End GC"
check_leak("Post-Construction")
print memoryUsage()
elif k == QKeyEvent.Key_M:
print memoryUsage()
app = QApplication(sys.argv)
w = Main()
app.setMainWidget(w)
w.show()
print "Focus the Window and press Enter for object creation / destruction, or
'M' for current memory usage\n"
print memoryUsage(),'\n'
app.exec_loop()
#------------------------------------------------------------------------------
# Sample Output:
[EMAIL PROTECTED]:~$ ./isolate_leak.py
Focus the Window and press Enter for object creation / destruction, or 'M'
for current memory usage
Current Memory Usage: RSS:18714624.0 Stk:40960.0 Data:3489792.0 Lib:26427392.0
Size:32927744.0
*** Creating 10000 LeakDialog's
AT Pre-Creating: MAX 'Size' MEMORY INCREASED FROM 31375360 TO 32968704
(+1593344)
AT Pre-Creating: MAX 'Data' MEMORY INCREASED FROM 2072576 TO 3489792
(+1417216)
AT Pre-Creating: MAX 'Lib' MEMORY INCREASED FROM 26304512 TO 26464256
(+159744)
AT Pre-Creating: MAX 'RSS' MEMORY INCREASED FROM 15441920 TO 18882560
(+3440640)
End Creating
Forcing GC
End GC
AT Post-Construction: MAX 'Size' MEMORY INCREASED FROM 32968704 TO
46891008 (+13922304)
AT Post-Construction: MAX 'Data' MEMORY INCREASED FROM 3489792 TO
17412096 (+13922304)
AT Post-Construction: MAX 'RSS' MEMORY INCREASED FROM 18882560 TO
32854016 (+13971456)
Current Memory Usage: RSS:32854016.0 Stk:40960.0 Data:17412096.0 Lib:26464256.0
Size:46891008.0
Current Memory Usage: RSS:32854016.0 Stk:40960.0 Data:17412096.0 Lib:26464256.0
Size:46891008.0
Current Memory Usage: RSS:32854016.0 Stk:40960.0 Data:17412096.0 Lib:26464256.0
Size:46891008.0
Current Memory Usage: RSS:32854016.0 Stk:40960.0 Data:17412096.0 Lib:26464256.0
Size:46891008.0
*** Creating 10000 LeakDialog's
End Creating
Forcing GC
End GC
AT Post-Construction: MAX 'RSS' MEMORY INCREASED FROM 32854016 TO
32919552 (+65536)
Current Memory Usage: RSS:32919552.0 Stk:40960.0 Data:17412096.0 Lib:26464256.0
Size:46891008.0
Current Memory Usage: RSS:32923648.0 Stk:40960.0 Data:17412096.0 Lib:26464256.0
Size:46891008.0
Current Memory Usage: RSS:32923648.0 Stk:40960.0 Data:17412096.0 Lib:26464256.0
Size:46891008.0
*** Creating 10000 LeakDialog's
AT Pre-Creating: MAX 'RSS' MEMORY INCREASED FROM 32919552 TO 32923648
(+4096)
End Creating
Forcing GC
End GC
AT Post-Construction: MAX 'Size' MEMORY INCREASED FROM 46891008 TO
47157248 (+266240)
AT Post-Construction: MAX 'Data' MEMORY INCREASED FROM 17412096 TO
17678336 (+266240)
AT Post-Construction: MAX 'RSS' MEMORY INCREASED FROM 32923648 TO
33189888 (+266240)
Current Memory Usage: RSS:33189888.0 Stk:40960.0 Data:17678336.0 Lib:26464256.0
Size:47157248.0
Current Memory Usage: RSS:33189888.0 Stk:40960.0 Data:17678336.0 Lib:26464256.0
Size:47157248.0
[EMAIL PROTECTED]:~$
-- System Information:
Debian Release: testing/unstable
APT prefers unstable
APT policy: (500, 'unstable')
Architecture: i386 (i586)
Kernel: Linux 2.6.8nah1-k6
Locale: LANG=C, LC_CTYPE=C
Versions of packages python-qt3 depends on:
ii python 2.3.3-7 An interactive high-level object-o
ii python2.3-qt3 3.13-4 Qt3 bindings for Python 2.3
-- no debconf information
--
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]