alexmojaki / alexmojaki/executing

Possible memory leak?

Đang mở
#33 12 bình luận 0 reaction 0 người được giao Xem trên GitHub
Ngôn ngữ chính
Python
Star
401
Fork
38
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

While debugging why [icecream](https://pypi.org/project/icecream/) has [issues with Qt](https://github.com/gruns/icecream/issues/118), I discovered that `executing.Source.executing` keeps some sort of hidden reference to the local variables of the function called. In the code sample below, the issue is noticeable by the fact that `method0` and `method1` show only one window while `method2` shows two windows (one being basically a black screen). This happens because in Qt widgets remain shown while someone is holding a reference to them.

```python
#!/usr/bin/env python3
import sys
import PySide6
from PySide6 import QtWidgets
from PySide6.QtCore import QLibraryInfo, qVersion
from PySide6.QtWidgets import QMainWindow
from PySide6.QtMultimediaWidgets import QVideoWidget

import inspect
import executing

def my_print(*args):
callFrame = inspect.currentframe().f_back
executing.Source.executing(callFrame)
return None

class MyWindow(QMainWindow):
def __init__(self):
super().__init__()

def showEvent(self, evt):
# If you replace method2 with method1 or method0, no window will appear for QVideoWidget
self.method2()

def method0(self):
self.setWindowTitle('Method 0')
camera_view = QVideoWidget()
camera_view.show()

def method1(self):
self.setWindowTitle('Method 1')
camera_view = QVideoWidget()
print(camera_view)
camera_view.show()

def method2(self):
self.setWindowTitle('Method 2')
camera_view = QVideoWidget()
my_print(camera_view)
camera_view.show()

def main():
print('Python {}.{}'.format(sys.version_info[0], sys.version_info[1]))
print(QLibraryInfo.build())
print(f"PySide6 version: {PySide6.__version__}")

app = QtWidgets.QApplication(sys.argv)
window = MyWindow()
window.show()
sys.exit(app.exec())

if __name__ == "__main__":
main()
```

Hướng dẫn đóng góp

Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.