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
PdfView stays on TopLevel.ScalingChanged after it leaves the visual tree, so a closed viewer and its document are never collected #599
Version: Broadside.Viewer.Avalonia 0.1.0-preview.10, Avalonia 12.1.6 (the package pins 12.1.4), .NET 10, Windows; seen headless (Avalonia.Headless) and by reading the code.
What happens.PdfView.OnAttachedToVisualTree subscribes topLevel.ScalingChanged += OnScalingChanged. OnDetachedFromVisualTree unsubscribes through TopLevel.GetTopLevel(this), which is already null when Avalonia calls it (the visual root is cleared before the override runs), so the -= never happens. Every PdfView that was ever shown in a window stays referenced by that window's ScalingChanged delegate, and through the view its controller, its last session's caches and whatever the host hung on it. Disposing the view does not help: Dispose does not unsubscribe either.
Repro (a window that outlives the viewer, as a tabbed app's main window does):
Closing the window releases them, which is why a test that closes its window does not see it.
Suggested fix. In OnDetachedFromVisualTree, unsubscribe from e.Root as TopLevel (the root it is leaving) instead of TopLevel.GetTopLevel(this); and unsubscribe in Dispose too.
Workaround we ship meanwhile: on the view's DetachedFromVisualTree event and on dispose, remove OnScalingChanged from (e.Root as TopLevel).ScalingChanged by reflection. Removing a handler that is not there does nothing, so it stays harmless once this is fixed.
Still present on main: src/Broadside.Viewer.Avalonia/PdfView.cs, OnDetachedFromVisualTree (around line 330) and Dispose (around line 268).
Activity
michaelstonis commentedon Nov 24, 2026
Viewer track: the viewer packages are not part of v1.0 (owner decision on #276), so this does not block 1.0.