You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
.NET object is never collected once a Python event handler has been attached, even after removing it (3.2.1, regression of #1972?) #2755
If a Python function is attached to an event of a .NET object, that object is never garbage collected, even after the handler is removed, the object is disposed, and both the Python and .NET collectors are forced. Without the handler, the same object is collected.
The 3.0.1 changelog lists a fix for this exact case ("Fixed objects leaking when Python attached event handlers to them even if they were later removed", #1972 / #1973). So this looks like a regression.
no handler: 0 of 5 still alive
handler attached, then removed: 5 of 5 still alive
handler attached, not removed: 5 of 5 still alive
Expected
In the first two cases, 0 of 5 still alive.
Arguably in the third as well, because in .NET an object that only references its own handler is collectable.
Notes
We see the same thing with a Python subclass of Form (__namespace__ set) that subscribes one of its own methods.
Impact: pywebview's WinForms backend (BrowserForm) attaches Python handlers to its own events. Every window that is created and destroyed stays in memory with its WebView2 control. Measured over 200 create/destroy cycles: about +28 MB, +100 threads and +300 GDI objects per 100 windows. Part of that has other causes on the pywebview side, which we are reporting there.
We only tested the .NET Framework runtime (netfx), which is what pywebview uses.
Activity