Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

After using "Reload Display" (Ctrl+R), the previous instance of the Display class is not deleted. #1114

Open
mattgibbs opened this issue Sep 25, 2024 · 0 comments

Comments

@mattgibbs
Copy link
Collaborator

Describe the bug
After using "Reload Display" (Ctrl+R), the previous instance of the Display class is not deleted. I suspect (but don't know for sure) that it is not getting garbage collected.

Expected behavior
The previous instance of the display class should not exist anymore.

Steps to Reproduce
The following code-only display file lets you see the problem happening:

from pydm import Display
from qtpy.QtWidgets import QLabel, QVBoxLayout, QHBoxLayout
from qtpy.QtCore import QTimer

class MyDisplay(Display):
    def __init__(self, parent=None, args=[]):
        super(MyDisplay, self).__init__(parent=parent, args=args)
        self.timer = QTimer(self)
        self.timer.setInterval(1000)
        self.timer.timeout.connect(self.tick)
        self.timer.start()
        self.setup_ui()

    def setup_ui(self):
        main = QHBoxLayout()
        sub = QVBoxLayout()
        for i in range(10):
            sub.addWidget(QLabel(str(i)))
        main.addLayout(sub)
        self.setLayout(main)

    def tick(self):
        print("Tick...")

    def ui_filename(self):
        return None

    def ui_filepath(self):
        return None

Open this display in PyDM, and in your terminal, you'll see "Tick..." get printed every second. Now do "Reload Display". You'll see that "Tick..." is now printed two times per second - a sign that the old instance of the display, along with its old timer, is still kicking around somewhere in memory.

Possible Solution
I suspect a reference to the Display class is getting stored somewhere at the PyDMApplication level (maybe something like the Rules evaluation engine?) that doesn't get cleared when Reload Display is called. The best way to solve that really depends on the details, but maybe something like using a weakref somewhere would work...

My Platform
Shouldn't matter, but I did my testing on RHEL7, Python 3.10.14, and PyDM 1.24.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant