mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Edit metadata dialog: Fix memory leak caused by Next/Previous buttons
This commit is contained in:
parent
3651d89db6
commit
f71f60ab0c
@ -910,14 +910,18 @@ class MetadataSingleDialog(ResizableDialog, Ui_MetadataSingleDialog):
|
|||||||
bytes(self.splitter.saveState()))
|
bytes(self.splitter.saveState()))
|
||||||
|
|
||||||
def break_cycles(self):
|
def break_cycles(self):
|
||||||
try:
|
# Break any reference cycles that could prevent python
|
||||||
self.view_format.disconnect()
|
# from garbage collecting this dialog
|
||||||
except:
|
def disconnect(signal):
|
||||||
pass # Fails if view format was never connected
|
try:
|
||||||
self.view_format = None
|
signal.disconnect()
|
||||||
self.db = None
|
except:
|
||||||
self.pi = None
|
pass # Fails if view format was never connected
|
||||||
self.cover_data = self.cpixmap = None
|
disconnect(self.view_format)
|
||||||
|
for b in ('next_button', 'prev_button'):
|
||||||
|
x = getattr(self, b, None)
|
||||||
|
if x is not None:
|
||||||
|
disconnect(x.clicked)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
from calibre.library import db
|
from calibre.library import db
|
||||||
@ -935,38 +939,17 @@ if __name__ == '__main__':
|
|||||||
d.reject()
|
d.reject()
|
||||||
del d
|
del d
|
||||||
|
|
||||||
for i in range(3):
|
for i in range(5):
|
||||||
gc.collect()
|
gc.collect()
|
||||||
before = memory()
|
before = memory()
|
||||||
|
|
||||||
gc.collect()
|
|
||||||
d = MetadataSingleDialog(None, 4, db)
|
d = MetadataSingleDialog(None, 4, db)
|
||||||
d.break_cycles()
|
|
||||||
d.reject()
|
d.reject()
|
||||||
|
d.break_cycles()
|
||||||
del d
|
del d
|
||||||
|
|
||||||
for i in range(3):
|
for i in range(5):
|
||||||
gc.collect()
|
gc.collect()
|
||||||
print 'Used memory:', memory(before)/1024.**2, 'MB'
|
print 'Used memory:', memory(before)/1024.**2, 'MB'
|
||||||
gc.collect()
|
|
||||||
|
|
||||||
'''
|
|
||||||
nmap, omap = {}, {}
|
|
||||||
for x in objects:
|
|
||||||
omap[id(x)] = x
|
|
||||||
for x in nobjects:
|
|
||||||
nmap[id(x)] = x
|
|
||||||
|
|
||||||
new_ids = set(nmap.keys()) - set(omap.keys())
|
|
||||||
print "New ids:", len(new_ids)
|
|
||||||
for i in new_ids:
|
|
||||||
o = nmap[i]
|
|
||||||
if o is objects:
|
|
||||||
continue
|
|
||||||
print repr(o)[:1050]
|
|
||||||
refs = gc.get_referrers(o)
|
|
||||||
for r in refs:
|
|
||||||
if r is objects or r is nobjects:
|
|
||||||
continue
|
|
||||||
print '\t', r
|
|
||||||
'''
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user