title: Ninject caching object, that should be disposed, memoryleak?
body: <p>Memory leak when the, no objects gets disposed in the weakreferencecollection inside ninject, what am I doing wrong or is there a huge error in ninject?</p>
  <p>When Kernal gets disposed then all the references gets disposed, from the weakreference collection, but when in this loop, even when there is no reference from code - the memory just explodes.</p>
  <pre><code>public class Program
  {
      private StandardKernel kernel;
  
      private static void Main(string[] args)
      {
          new Program().Run();
      }
  
      public void Run()
      {
          kernel = new StandardKernel(new NinjectSettings() { LoadExtensions = false });
          kernel.Bind&lt;Root&gt;().ToSelf();
          kernel.Bind&lt;Foo&gt;().ToSelf().InCallScope();
  
          while (true)
          {
              Process();
  
              Thread.Sleep(500);
  
              GC.Collect();
              GC.WaitForPendingFinalizers();
          }
      }
  
      public void Process()
      {
          Root root = kernel.Get&lt;Root&gt;();
          Root root2 = kernel.Get&lt;Root&gt;();
      }
  
      public class Root
      {
          private Foo _test;
  
          public Root(Foo foofac)
          {
              Id = Guid.NewGuid();
              _test = foofac;
          }
  
          protected Guid Id { get; set; }
      }
  
      public class Foo
      {
      }
  }
  </code></pre>
  <hr />
  <h1>Update</h1>
  <p>Ive tried with Named scope and even using a Factory like in the excample:
  <a href="http://www.planetgeek.ch/2012/04/23/future-of-activation-blocks/" rel="nofollow noreferrer">http://www.planetgeek.ch/2012/04/23/future-of-activation-blocks/</a>
  but still in a memoryprofiler the weakreference collection is exploding over time, and this is not nice... My current test code is:</p>
  <pre><code>public class Program
  {
      private StandardKernel kernel;
  
      private static void Main(string[] args)
      {
          new Program().Run();
      }
  
      public void Run()
      {
          kernel = new StandardKernel(new NinjectSettings() { LoadExtensions = false });
          kernel.Load&lt;FuncModule&gt;();
  
          kernel.Bind&lt;IRootFactory&gt;().ToFactory();
          var scopeParameterName = &quot;scopeRoot&quot;;
          kernel.Bind&lt;Root&gt;().ToSelf().DefinesNamedScope(scopeParameterName);
          kernel.Bind&lt;Foo&gt;().ToSelf().InNamedScope(scopeParameterName);
          
  
          while (true)
          {
              Process();
  
              GC.Collect();
              GC.WaitForPendingFinalizers();
  
              Thread.Sleep(500);
          }
      }
  
      public void Process()
      {
          Root root = kernel.Get&lt;IRootFactory&gt;().CreateRoot();
          Root root2 = kernel.Get&lt;IRootFactory&gt;().CreateRoot();
      }
  
      public class Root
      {
          private Foo _test;
  
          public Root(Foo foofac)
          {
              Id = Guid.NewGuid();
              _test = foofac;
          }
  
          protected Guid Id { get; set; }
      }
  
      public class Foo
      {
      }
  
      public  interface IRootFactory
      {
          Root CreateRoot();
      }
  }
  </code></pre>