connect()'s refcounting behavior seems buggy, and should be documented

Kovid Goyal kovid at kovidgoyal.net
Sat Mar 19 02:28:36 GMT 2022


On Fri, Mar 18, 2022 at 05:26:13PM +0000, Phil Thompson wrote:
> I've changed the PyQt6 behaviour to keep a reference to bound methods. I'm
> not going to change PyQt5 as stability (avoiding unexpected consequences) is
> more important than correctness so late in its lifecycle.

Is the reference a weak or a strong reference? If its a strong reference
it will create reference cycles. Something as simple as:

class Widget(QDialog):

    def __init__(self):
        QDialog.__init__(self)
        self.bb = QDialogButtonBox(self)
        self.bb.accepted.connect(self.accept)

    def accept(self):
        ...

is now a reference cycle that the python garbage collector cannot
collect.



More information about the PyQt mailing list