Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memory leak and perf getting worse for TryGet with missing bindings #398

Open
Julie-BC opened this issue Apr 7, 2023 · 1 comment
Open
Labels
Milestone

Comments

@Julie-BC
Copy link

Julie-BC commented Apr 7, 2023

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
image
but a memory leak occurs and performance decreases
image
[...]
image

And this seems to be because of missing bindings adds
image

@scott-xu
Copy link
Member

scott-xu commented Apr 7, 2023

Thanks for the detailed analysis. Good to know it is fixed in latest 4.0.0-beta.

@scott-xu scott-xu added the Bug label Apr 7, 2023
@scott-xu scott-xu added this to the 4.0 milestone Apr 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants