<div dir="ltr"><font color="#1a1a1a"><span style="white-space:pre-wrap"><b><font face="helvetica neue, arial, sans-serif" style="font-size:12.96px">The following pytest test leaks memory (the memory and other kernel objects like GDI and User handles keep increasing at every iteration and never go back down until test exits):
</font><font face="monospace" size="1">import pytest
from PyQt5.QtCore import QTimer
from PyQt5.QtWidgets import QApplication, QGraphicsScene, QGraphicsView
class TestCase:
@pytest.mark.parametrize('dummy', range(1000))
def test_empty(self, dummy):
# self.view = None # does NOT fix the leak if uncommented!
self.app = QApplication.instance()
if self.app is None:
self.app = QApplication([])
self.view = QGraphicsView()
self.view.setFixedSize(600, 400)
self.view.setScene(QGraphicsScene())
self.view.show()
QTimer.singleShot(100, self.app.exit)
self.app.exec()
# self.view = None # FIXES the leak if uncommented!</font></b></span></font><br><div><font color="#1a1a1a" face="helvetica neue, arial, sans-serif"><span style="font-size:12.96px;white-space:pre-wrap"><b><br></b></span></font></div><div><font color="#1a1a1a" face="helvetica neue, arial, sans-serif"><span style="font-size:12.96px;white-space:pre-wrap"><b>Leak stops if last line is uncommented, but this sort of fix is error-prone solution as every developer has to remember to do this for each test. There are a couple other ways of stopping the leak and creating the leak, details are in my post at </b></span><span style="white-space:pre-wrap"><b><a href="http://stackoverflow.com/questions/40478600/mem-leak-in-pyqt-test-with-pytest">http://stackoverflow.com/questions/40478600/mem-leak-in-pyqt-test-with-pytest</a>. </b></span></font></div><div><font color="#1a1a1a" face="helvetica neue, arial, sans-serif"><span style="white-space:pre-wrap"><b><br></b></span></font></div><div><font color="#1a1a1a" face="helvetica neue, arial, sans-serif"><span style="white-space:pre-wrap"><b>Oliver</b></span></font></div></div><div dir="ltr">-- <br></div><div data-smartmail="gmail_signature"><div dir="ltr">Oliver</div></div>