alexmojaki / alexmojaki/executing

Possible memory leak?

オープン
#33 コメント 12 件 リアクション 0 件 担当者 0 名 GitHub で見る
主要言語
Python
スター
401
フォーク
38
PR マージ指標
30日以内にマージされた PR はありません

説明

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()
```

コントリビューションガイド

このリポジトリのコントリビューションガイドは索引されていません

評価

この issue はまだ評価されていません。

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。