alexmojaki / alexmojaki/executing

Possible memory leak?

Offen
#33 12 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
Vorherrschende Sprache
Python
Sterne
401
Forks
38
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Beschreibung

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

Beitragsleitfaden

Für dieses Repository ist kein Beitragsleitfaden indexiert

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.