我现在正在开发一个Python应用程序,它使用PyQt5和CFFI绑定到libgphoto2。在
我有这段代码,它将每隔1/60秒轮询一次相机,以获得预览图像,然后计划在屏幕上绘制。在
def showPreview(self):
# Do we have a camera loaded at the moment?
if self.camera:
try:
# get data from the camera & turn it into a pixmap
self.__buffer = self.camera.getPreview().scaled(self.size(), Qt.KeepAspectRatio) # Scale it
# Schedule a redraw
self.update()
# Setup another show preview in 1/60 of a second
QTimer.singleShot(1000 // 60, self.showPreview)
except GPhoto2Error as e:
# Ignore any errors from libgphoto2
pass
getPreview()
方法返回QImage
类型。在
当我用连接到应用程序的摄像头运行这个程序时,我注意到我的系统内存使用率一直在不断上升。是的,我已经让它运行了大约10分钟。一开始它的使用率为0.5%,现在已经接近20%。在
如果我错了,请纠正我的错误,但是Python的GC不应该启动并删除旧的QImage
对象吗。我怀疑他们逗留的时间比他们应该的要长。在
如果有帮助的话,我在使用QImage和QPixmap的应用程序上发生了类似的内存泄漏。每次上传图片时,内存都以2%的速度增长。通过使用QPixmap.缩放(...., 快速转换)我实现了每幅图像增加0.2%。这个问题仍然存在,但小了10倍。我的代码中没有其他任何更改。所以它必须与QImage/QPixmap的析构函数相关。在
相关问题 更多 >
编程相关推荐