-
Notifications
You must be signed in to change notification settings - Fork 527
Open
Description
Hi NInject Team,
We have detected a memory leak with NInject 3.3.6
This would have been solved with last changes for 4.0.0-beta but I think important to report it.
It's depending on the context but it is easily reproducible.
Just make sure about both conditions :
- The element was not previously registered
- The resolve is tried about a concrete type (not an interface)
using System;
using System.Diagnostics;
using System.Threading;
using Ninject;
namespace NInjectMemoryLeak;
/// <summary>
/// Program
/// </summary>
public static class Program
{
public static void Main()
{
using var container = new StandardKernel();
for (var i = 0; i < int.MaxValue; i++)
{
var watch = Stopwatch.StartNew();
container.TryGet<object>("toto");
var duration = watch.Elapsed;
Console.WriteLine($"{i} => {duration}");
if (i % 1000 == 0)
{
GC.Collect();
Thread.Sleep(1000);
}
}
Console.Read();
}
}
You will have good perf at first

but a memory leak occurs and performance decreases

[...]

And this seems to be because of missing bindings adds
