How do you diagnose and fix memory leaks in MAUI?
Short answer
Common causes are strong event subscriptions, static references to pages/view models, and un-disposed handlers. Use the platform profilers (Xcode Instruments, Android Studio Memory Profiler, dotnet-trace/dotnet-gcdump).
Advertisement
AModel answer
Common causes are strong event subscriptions, static references to pages/view models, and un-disposed handlers. Use the platform profilers (Xcode Instruments, Android Studio Memory Profiler, dotnet-trace/dotnet-gcdump). Prefer WeakReferenceMessenger, unsubscribe events, and null out BindingContext when appropriate.
// Leak-prone: strong subscription that outlives the page
_service.DataChanged += OnDataChanged;
// Fix: unsubscribe in OnDisappearing / use weak messenger
protected override void OnDisappearing()
=> _service.DataChanged -= OnDataChanged;Real-world example
A navigation loop that grew memory was traced to pages kept alive by an event handler; unsubscribing let them be collected.
Likely follow-ups
- Why do events cause leaks? | Which tools profile MAUI memory?
Related topics