LeakDetector.Maui
1.0.4
dotnet add package LeakDetector.Maui --version 1.0.4
NuGet\Install-Package LeakDetector.Maui -Version 1.0.4
<PackageReference Include="LeakDetector.Maui" Version="1.0.4" />
<PackageVersion Include="LeakDetector.Maui" Version="1.0.4" />
<PackageReference Include="LeakDetector.Maui" />
paket add LeakDetector.Maui --version 1.0.4
#r "nuget: LeakDetector.Maui, 1.0.4"
#:package LeakDetector.Maui@1.0.4
#addin nuget:?package=LeakDetector.Maui&version=1.0.4
#tool nuget:?package=LeakDetector.Maui&version=1.0.4
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
๐ง Recommended Workflow
- Navigate between pages multiple times
- Observe console output
- Identify leaked objects
- 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 releaseUpcoming 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 | Versions 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. |
-
net8.0
- LeakDetector.Core (>= 1.0.3)
- Microsoft.Maui.Controls (>= 10.0.51)
-
net9.0
- LeakDetector.Core (>= 1.0.3)
- Microsoft.Maui.Controls (>= 10.0.51)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.