PyQt:删除类对象,调用析构函数但不释放内存 [英] PyQt: class object deleting, calling destructors but memory not freeing
本文介绍了PyQt:删除类对象,调用析构函数但不释放内存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用 pyQt
创建一个工具,但面临内存泄漏问题.
I am creating a tool using pyQt
but facing memory leakage issue.
当我使用自己的垃圾桶从 UI 中删除包含 python 和 pyQt 成员变量的对象时,它会调用相应类的析构函数.但是当我从终端运行 'top' 命令时,内存不会被释放,并且只要我使用应用程序就会继续占用并最终崩溃.
When I delete an object containing python and pyQt member variables from UI using my own trash, it calls up the destructor of the respective class. But when I run 'top' command from terminal the memory is not freed and keeps on occupying as long as I use the applications and finally crashes up.
推荐答案
我以前就遇到过这个问题.我使用了这种方法,对我来说效果很好:
I already faced this problem before. I used this approach and it worked fine for me:
widget.setParent(None)
widget.deleteLater()
希望有帮助!
也请看这个:https://stackoverflow.com/a/30245816/6337523
这篇关于PyQt:删除类对象,调用析构函数但不释放内存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文