开发者

Memory not deallocated - PyQt4

开发者 https://www.devze.com 2023-02-17 06:26 出处:网络
It might be the bindings (SIP) or even python, but I have a problem with Qt (pyqt4). I have a QTabWidget, and inside it I put widgets one can clos开发者_如何学Ce.

It might be the bindings (SIP) or even python, but I have a problem with Qt (pyqt4).

I have a QTabWidget, and inside it I put widgets one can clos开发者_如何学Ce.

I have a widget that allocates about 400mb of memory. I have not set a parent, and I call deleteLater() on close but nothing happens. Even calling the python's gc does not work:

import gc
gc.collect()

Now when closing the widgets from the QTabWidget without using deleteLater() more and more memory is allocated. So lets say I open up 4 tabs of the memory-heavy widget, I use around 1.6GB memory. If I close them all, and open a new, I am now up to 2GB of memory usage.

If I use the deleteLater(), after closing the 4 tabs, I do not go up to 2GB opening a new one, then I have to open 5 tabs. But, and here is the problem, 1.6GB is still allocated for the process (python) even tho all widgets are closed, and deleteLater has been called.

Thanks


I had this - somewhere you have an reference to your widget, and that reference has been counted... the only way to delete that widget is to make sure that there are no remaining references so python can garbage-collect it.

At least you don't end up with a dangling reference like C++, which can lead to some nasty crashes...


This can actually be useful - if you create a class with a class-level list of its members, you can recycle old objects and never have them garbage-collected

0

精彩评论

暂无评论...
验证码 换一张
取 消