mirror of
https://github.com/ankitects/anki.git
synced 2025-11-08 05:37:12 -05:00
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:
parent
b65e8334d5
commit
a1caa93054
6 changed files with 29 additions and 2 deletions
|
|
@ -7,8 +7,9 @@ import aqt.forms
|
||||||
from aqt import appVersion
|
from aqt import appVersion
|
||||||
from aqt.utils import openLink
|
from aqt.utils import openLink
|
||||||
|
|
||||||
def show(parent):
|
def show(mw):
|
||||||
dialog = QDialog(parent)
|
dialog = QDialog(mw)
|
||||||
|
mw.setupDialogGC(dialog)
|
||||||
abt = aqt.forms.about.Ui_About()
|
abt = aqt.forms.about.Ui_About()
|
||||||
abt.setupUi(dialog)
|
abt.setupUi(dialog)
|
||||||
abouttext = "<center><img src='qrc:/icons/anki-logo-thin.png'></center>"
|
abouttext = "<center><img src='qrc:/icons/anki-logo-thin.png'></center>"
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,7 @@ class AddCards(QDialog):
|
||||||
|
|
||||||
def __init__(self, mw):
|
def __init__(self, mw):
|
||||||
QDialog.__init__(self, None, Qt.Window)
|
QDialog.__init__(self, None, Qt.Window)
|
||||||
|
mw.setupDialogGC(self)
|
||||||
self.mw = mw
|
self.mw = mw
|
||||||
self.form = aqt.forms.addcards.Ui_Dialog()
|
self.form = aqt.forms.addcards.Ui_Dialog()
|
||||||
self.form.setupUi(self)
|
self.form.setupUi(self)
|
||||||
|
|
|
||||||
|
|
@ -466,6 +466,7 @@ class Browser(QMainWindow):
|
||||||
aqt.dialogs.close("Browser")
|
aqt.dialogs.close("Browser")
|
||||||
self.teardownHooks()
|
self.teardownHooks()
|
||||||
self.mw.maybeReset()
|
self.mw.maybeReset()
|
||||||
|
self.mw.gcWindow(self)
|
||||||
evt.accept()
|
evt.accept()
|
||||||
|
|
||||||
def canClose(self):
|
def canClose(self):
|
||||||
|
|
@ -1375,6 +1376,7 @@ update cards set usn=?, mod=?, did=? where id in """ + scids,
|
||||||
|
|
||||||
def onFindDupes(self):
|
def onFindDupes(self):
|
||||||
d = QDialog(self)
|
d = QDialog(self)
|
||||||
|
self.mw.setupDialogGC(d)
|
||||||
frm = aqt.forms.finddupes.Ui_Dialog()
|
frm = aqt.forms.finddupes.Ui_Dialog()
|
||||||
frm.setupUi(d)
|
frm.setupUi(d)
|
||||||
restoreGeom(d, "findDupes")
|
restoreGeom(d, "findDupes")
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,7 @@ class CardLayout(QDialog):
|
||||||
|
|
||||||
def __init__(self, mw, note, ord=0, parent=None, addMode=False):
|
def __init__(self, mw, note, ord=0, parent=None, addMode=False):
|
||||||
QDialog.__init__(self, parent or mw, Qt.Window)
|
QDialog.__init__(self, parent or mw, Qt.Window)
|
||||||
|
mw.setupDialogGC(self)
|
||||||
self.mw = aqt.mw
|
self.mw = aqt.mw
|
||||||
self.parent = parent or mw
|
self.parent = parent or mw
|
||||||
self.note = note
|
self.note = note
|
||||||
|
|
|
||||||
21
aqt/main.py
21
aqt/main.py
|
|
@ -5,6 +5,8 @@
|
||||||
import re
|
import re
|
||||||
import signal
|
import signal
|
||||||
import zipfile
|
import zipfile
|
||||||
|
import gc
|
||||||
|
import time
|
||||||
|
|
||||||
from send2trash import send2trash
|
from send2trash import send2trash
|
||||||
from aqt.qt import *
|
from aqt.qt import *
|
||||||
|
|
@ -1139,3 +1141,22 @@ Please ensure a profile is open and Anki is not busy, then try again."""),
|
||||||
return
|
return
|
||||||
# import
|
# import
|
||||||
self.handleImport(buf)
|
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()
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,7 @@ class DeckStats(QDialog):
|
||||||
|
|
||||||
def __init__(self, mw):
|
def __init__(self, mw):
|
||||||
QDialog.__init__(self, mw, Qt.Window)
|
QDialog.__init__(self, mw, Qt.Window)
|
||||||
|
mw.setupDialogGC(self)
|
||||||
self.mw = mw
|
self.mw = mw
|
||||||
self.name = "deckStats"
|
self.name = "deckStats"
|
||||||
self.period = 0
|
self.period = 0
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue