fix mem leaks in dialogs

- ensure we're cleaning them up after they're rejected
- run the garbage collector afterwards so the qwebengineprocess
  instances get cleaned up
This commit is contained in:
Damien Elmes 2016-07-04 13:22:35 +10:00
parent b65e8334d5
commit a1caa93054
6 changed files with 29 additions and 2 deletions

View file

@ -7,8 +7,9 @@ import aqt.forms
from aqt import appVersion
from aqt.utils import openLink
def show(parent):
dialog = QDialog(parent)
def show(mw):
dialog = QDialog(mw)
mw.setupDialogGC(dialog)
abt = aqt.forms.about.Ui_About()
abt.setupUi(dialog)
abouttext = "<center><img src='qrc:/icons/anki-logo-thin.png'></center>"

View file

@ -16,6 +16,7 @@ class AddCards(QDialog):
def __init__(self, mw):
QDialog.__init__(self, None, Qt.Window)
mw.setupDialogGC(self)
self.mw = mw
self.form = aqt.forms.addcards.Ui_Dialog()
self.form.setupUi(self)

View file

@ -466,6 +466,7 @@ class Browser(QMainWindow):
aqt.dialogs.close("Browser")
self.teardownHooks()
self.mw.maybeReset()
self.mw.gcWindow(self)
evt.accept()
def canClose(self):
@ -1375,6 +1376,7 @@ update cards set usn=?, mod=?, did=? where id in """ + scids,
def onFindDupes(self):
d = QDialog(self)
self.mw.setupDialogGC(d)
frm = aqt.forms.finddupes.Ui_Dialog()
frm.setupUi(d)
restoreGeom(d, "findDupes")

View file

@ -20,6 +20,7 @@ class CardLayout(QDialog):
def __init__(self, mw, note, ord=0, parent=None, addMode=False):
QDialog.__init__(self, parent or mw, Qt.Window)
mw.setupDialogGC(self)
self.mw = aqt.mw
self.parent = parent or mw
self.note = note

View file

@ -5,6 +5,8 @@
import re
import signal
import zipfile
import gc
import time
from send2trash import send2trash
from aqt.qt import *
@ -1139,3 +1141,22 @@ Please ensure a profile is open and Anki is not busy, then try again."""),
return
# import
self.handleImport(buf)
# GC
##########################################################################
# run the garbage collector after object is deleted so we don't leave
# expensive web engine processes lying around
def setupDialogGC(self, obj):
obj.finished.connect(lambda o=obj: self.gcWindow(obj))
def gcWindow(self, obj):
obj.deleteLater()
t = QTimer(self)
t.timeout.connect(self._onCollect)
t.setSingleShot(True)
# will run next time queue is idle
t.start(0)
def _onCollect(self):
gc.collect()

View file

@ -14,6 +14,7 @@ class DeckStats(QDialog):
def __init__(self, mw):
QDialog.__init__(self, mw, Qt.Window)
mw.setupDialogGC(self)
self.mw = mw
self.name = "deckStats"
self.period = 0