Created
December 13, 2021 21:36
-
-
Save j9ac9k/147f6319b5806051bb45d09fd7ab8947 to your computer and use it in GitHub Desktop.
lambda python reference count
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from pyqtgraph.Qt import QtWidgets | |
import weakref | |
import gc | |
class MyButton(QtWidgets.QPushButton): | |
def __init__(self, *args, **kwds): | |
super().__init__(*args, **kwds) | |
self.clicked.connect(lambda : self.hello()) | |
# self.clicked.connect(lambda: QtWidgets.QApplication.instance().exit()) | |
# self.clicked.connect(self.hello) | |
def hello(self): | |
QtWidgets.QApplication.instance().exit() | |
app = QtWidgets.QApplication([]) | |
button = MyButton("Hello") | |
button.show() | |
app.exec() if hasattr(app, 'exec') else app.exec_() | |
ref = weakref.ref(button) | |
del button | |
print(ref()) | |
gc.collect() | |
print(ref()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment