MemoryLeakDetector.Analyzers 1.0.1

dotnet add package MemoryLeakDetector.Analyzers --version 1.0.1
                    
NuGet\Install-Package MemoryLeakDetector.Analyzers -Version 1.0.1
                    
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="MemoryLeakDetector.Analyzers" Version="1.0.1">
  <PrivateAssets>all</PrivateAssets>
  <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="MemoryLeakDetector.Analyzers" Version="1.0.1" />
                    
Directory.Packages.props
<PackageReference Include="MemoryLeakDetector.Analyzers">
  <PrivateAssets>all</PrivateAssets>
  <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
                    
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 MemoryLeakDetector.Analyzers --version 1.0.1
                    
#r "nuget: MemoryLeakDetector.Analyzers, 1.0.1"
                    
#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 MemoryLeakDetector.Analyzers@1.0.1
                    
#: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=MemoryLeakDetector.Analyzers&version=1.0.1
                    
Install as a Cake Addin
#tool nuget:?package=MemoryLeakDetector.Analyzers&version=1.0.1
                    
Install as a Cake Tool

MemoryLeakDetector.Analyzers

Roslyn analyzers for detecting memory leaks and performance issues in .NET code.

Installation

dotnet add package MemoryLeakDetector.Analyzers

What It Detects?

🟢 Memory Leak Warnings (Green Squiggle)

Rule Description
MLD001 HttpClient created per request (causes socket exhaustion)
MLD002 Class has disposable field but doesn't implement IDisposable
MLD003 Async void method (exceptions cannot be caught)
MLD004 Timer field without IDisposable implementation

⚪ Performance Suggestions (Gray Dots)

Rule Description
PERF001 String concatenation in loop (use StringBuilder)
PERF002 ContainsKey + indexer (use TryGetValue)
PERF003 ToLower/ToUpper for comparison (use StringComparison)

Examples

MLD001 - HttpClient per request

// ❌ Bad - creates socket exhaustion
public async Task<string> GetData()
{
    var client = new HttpClient();  // Warning: MLD001
    return await client.GetStringAsync(url);
}

// ✅ Good - reuse HttpClient
private static readonly HttpClient _client = new HttpClient();
public async Task<string> GetData()
{
    return await _client.GetStringAsync(url);
}

MLD002 - Missing IDisposable

// ❌ Bad - FileStream not disposed
public class MyService
{
    private FileStream _file;  // Warning: MLD002
}

// ✅ Good - implements IDisposable
public class MyService : IDisposable
{
    private FileStream _file;
    public void Dispose() => _file?.Dispose();
}

PERF001 - String concat in loop

// ❌ Bad - creates many temporary strings
var result = "";
foreach (var item in items)
{
    result += item;  // Info: PERF001
}

// ✅ Good - use StringBuilder
var sb = new StringBuilder();
foreach (var item in items)
{
    sb.Append(item);
}

Configuration

You can configure rule severity in .editorconfig:

# Disable a rule
dotnet_diagnostic.MLD001.severity = none

# Make a rule an error (fails build)
dotnet_diagnostic.MLD002.severity = error

# Change performance rules to warnings
dotnet_diagnostic.PERF001.severity = warning

License

MIT

There are no supported framework assets in this package.

Learn more about Target Frameworks and .NET Standard.

  • .NETStandard 2.0

    • No dependencies.

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.1 4,405 12/22/2025
1.0.0 300 12/17/2025