Dispose problem if Owner == Container and ReuseScope == None

Jan 3, 2010 at 8:47 PM
Edited Jan 9, 2010 at 9:15 AM

Consider the following test. It fails.

It means, that in the case Owner == Container and ReuseScope == None the container doesnt guarantee, that all objects will be disposed. This problem is induced by weak references to created objects.

public class Disp : IFoo, IDisposable
      public static int i;
      public void Dispose()
    public void ContainerOwnedNonReuseInstacesAreDisposed()
      var container = new Container();
      container.Register<IFoo>(c => new Disp())




      Assert.AreEqual(1, Disp.i);

Oct 2, 2010 at 6:44 AM

if your object holds on to unmanaged resources and really needs disposable, you should implement the finalizable pattern and that would cover this scenario perfectly.

if funq kept those references just to dispose them later on, they would never die, and for a global factory container that would mean infinite memory leak.