LeakDetector.Maui 1.0.4

dotnet add package LeakDetector.Maui --version 1.0.4
                    
NuGet\Install-Package LeakDetector.Maui -Version 1.0.4
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="LeakDetector.Maui" Version="1.0.4" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="LeakDetector.Maui" Version="1.0.4" />
                    
Directory.Packages.props
<PackageReference Include="LeakDetector.Maui" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add LeakDetector.Maui --version 1.0.4
                    
#r "nuget: LeakDetector.Maui, 1.0.4"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package LeakDetector.Maui@1.0.4
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=LeakDetector.Maui&version=1.0.4
                    
Install as a Cake Addin
#tool nuget:?package=LeakDetector.Maui&version=1.0.4
                    
Install as a Cake Tool

LeakDetector.Maui

A lightweight memory leak detection library for .NET MAUI applications. Helps identify retained pages, view models, and long-lived objects using WeakReference.


๐Ÿš€ Installation

dotnet add package LeakDetector.Maui

โš™๏ธ Setup

Register the leak detector in your MAUI app:

builder.Services.AddLeakDetector();

Enable automatic tracking:

App.Current.UseLeakDetector();

๐Ÿ“ฑ How It Works

The library automatically tracks:

  • Pages (ContentPage, Shell, etc.)
  • ViewModels (BindingContext)
  • Object lifetime after navigation

No manual wiring required.


๐Ÿ” Example

public partial class MainPage : ContentPage
{
    public MainPage()
    {
        InitializeComponent();
    }
}

๐Ÿ‘‰ Navigate to and from this page multiple times. If it is not garbage collected, it will be reported.


๐Ÿ“Š Output

Leak detection results are written to the console:

โŒ MainPage [Page] - Alive for 12s
โŒ MainViewModel [VM] - Alive for 12s

๐Ÿงช Manual Tracking (Optional)

Track custom objects:

public class MyService
{
    public MyService(ILeakDetector detector)
    {
        detector.Track(this, "Service");
    }
}

โš™๏ธ Configuration

builder.Services.AddLeakDetector(options =>
{
    options.EnableAutoTracking = true;
    options.CheckDelay = TimeSpan.FromSeconds(3);
});

๐Ÿง  What It Detects

  • Pages not released after navigation
  • ViewModels retained in memory
  • Incorrect DI lifetimes (e.g., Singleton misuse)
  • Long-living objects

โš ๏ธ Limitations

  • Does not identify exact root cause of leaks
  • Does not detect native memory leaks
  • For deep analysis, use tools like dotnet-dump

  1. Navigate between pages multiple times
  2. Observe console output
  3. Identify leaked objects
  4. Fix references (events, static fields, DI lifetimes)

๐Ÿงฉ Architecture

  • LeakDetector.Core โ†’ Core tracking engine
  • LeakDetector.Maui โ†’ MAUI lifecycle integration

๐Ÿ› ๏ธ Best Practices

  • Use in debug/development builds only
  • Disable in production environments
  • Focus on navigation-heavy pages

๐Ÿ“ฆ Versioning

  • 1.0.1 โ†’ Initial release

  • Upcoming features:

    • UI dashboard
    • Stack trace capture
    • Advanced diagnostics

๐Ÿค Contributing

Contributions are welcome. Feel free to open issues or submit pull requests.


๐Ÿ“„ License

MIT License

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.4 103 4/7/2026
1.0.3 98 4/7/2026
1.0.1 101 4/7/2026
1.0.0 98 4/7/2026