Python / PyQt4内存泄漏

时间:2018-07-12 00:28:28

标签: python pyqt4

我正在编写一个信息亭式幻灯片Python(2.7)和PyQt4程序,该程序本质上读取一个装有jpeg图像的目录,然后将它们显示在图像之间逐渐消失,等等。某处有内存泄漏,我很确定这是在淡入淡出过程中。我的淡入淡出过程基于此处定义的技术:

https://wiki.python.org/moin/PyQt/Fading%20Between%20Widgets

除了使用QCalendarWidget和QTextEdit之外,我使用两个QGraphicsViews。

为了解决内存泄漏,我修改了以下内容:

painter = QPainter()

创建一次在FaderWidget的__init __()中定义的对象:

self.painter = QPainter()

最近,我尝试使用valgrind来帮助调试此问题。我都尝试过:

valgrind --tool=memcheck python foo.py
valgrind --leak-check=full python foo.py

,但是不确定如何有效地解释和使用它返回的数据。 valgrind的首次使用返回:

==22436== HEAP    SUMMARY:
==22436==     in use at exit: 419,841,996 bytes in 58,236 blocks
==22436==   total heap usage: 890,500 allocs, 832,264 frees, 1,159,349,520 bytes allocated
==22436==
==22436== LEAK SUMMARY:
==22436==    definitely lost: 14,518 bytes in 54 blocks
==22436==    indirectly lost: 50,006 bytes in 1,476 blocks
==22436==      possibly lost: 117,696 bytes in 317 blocks
==22436==    still reachable: 419,659,776 bytes in 56,389 blocks
==22436==         suppressed: 0 bytes in 0 blocks

最后,每个QGraphicsView()中的图像都按如下方式加载:

self.path1      = self.imageList[self.count]
self.pixImage1  = QtGui.QImage(self.path1)
self.pixNormal1 = QtGui.QPixmap.fromImage(self.pixImage1)
self.pixScaled1 = self.pixNormal1.scaled( self.PixFrame.size(), QtCore.Qt.KeepAspectRatio, QtCore.Qt.SmoothTransformation)

QImage()和QPixmap()调用是否可能未被垃圾回收并正在累积?

有人会对如何解决这个问题有任何想法或建议吗?

谢谢

0 个答案:

没有答案