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
NavigationView: removed menu items are never collected while the NavigationView lives #25970
A NavigationViewItem, NavigationViewItemHeader or NavigationViewItemSeparator removed from a NavigationView is never garbage collected while the NavigationView lives. Its content and DataContext stay in memory with it. In an app whose shell NavigationView lives for the app's lifetime, every menu item ever removed (e.g. a dynamic MenuItemsSource that gets refreshed) accumulates.
The items listen to the NavigationView's SplitView (IsPaneOpen, DisplayMode, CompactPaneLength) through RegisterPropertyChangedCallback, which the SplitView holds strongly. Items only unregister when their template is re-applied, and headers and separators never unregister. Retention path: NavigationView → SplitView → property-changed registrations → callback → item.
Expected behavior 🎯
A menu item removed from the NavigationView can be collected once nothing else references it, as on WinUI, whose handlers don't keep the item alive.
How to reproduce it (as minimally and precisely as possible) 🔬
varnv=newNavigationView{PaneDisplayMode=NavigationViewPaneDisplayMode.Left,IsPaneOpen=true};nv.MenuItems.Add(newNavigationViewItem{Content="Kept"});// show nv and wait for it to loadvarweak=AddItem(nv);// [MethodImpl(NoInlining)]: adds a NavigationViewItem (or header/separator), returns a WeakReference to it// wait for layoutnv.MenuItems.RemoveAt(1);// wait for layout; remove one more item too, since ItemsRepeater (like WinUI) keeps the last cleared element in its cached ElementClearing argsGC.Collect();GC.WaitForPendingFinalizers();// weak.IsAlive is still true while nv is alive
Workaround 🛠️
None short of discarding the whole NavigationView.
Affected platforms 📱💻🖥️
All platforms 🌍
Uno.Sdk version (and other relevant versions) 📦
Current master. Found by code audit, following the same pattern fixed in AnimatedIcon by #25948.
Activity
fix(NavigationView): Don't root menu items from the SplitView