.NET MAUI › Performance & Optimization

How do you diagnose and fix memory leaks in MAUI?

Intermediate

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.

Common follow-ups: Why do events cause leaks? | Which tools profile MAUI memory?