alexmojaki / alexmojaki/executing

Possible memory leak?

Aberta
#33 12 comentários 0 reações 0 responsáveis Ver no GitHub
Linguagem predominante
Python
Estrelas
401
Forks
38
Métricas de merge de PRs
Nenhum PR com merge em 30d

Descrição

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

Guia de contribuição

Nenhum guia de contribuição indexado para este repositório

Avaliação

Esta issue ainda não foi avaliada.

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.