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 using typed factory facility #98

Closed
ktam33 opened this issue Sep 14, 2015 · 3 comments
Closed

memory leak using typed factory facility #98

ktam33 opened this issue Sep 14, 2015 · 3 comments

Comments

@ktam33
Copy link

ktam33 commented Sep 14, 2015

The following code snippet leads to a memory leak due to dynamically loaded assemblies that are not cleaned up. The performance monitor counter [.NET Clr Loading -> Current Assemblies] can be used to see the issue.

While the usage of Windsor here is not ideal (repeated instantiation of the container), it should probably still be able to clean up after itself properly.

There has been some discussion of this issue here as well: http://stackoverflow.com/questions/14731058/castle-windsor-interceptor-memory-leak

class Program
{
    static void Main(string[] args)
    {
        while (true)
        {
            using (var container = new WindsorContainer())
            {
                container.Kernel.AddFacility<TypedFactoryFacility>();
                container.Register(Component.For<IMyFactory>().AsFactory());

                var myComponent = container.Resolve<IMyFactory>();
                container.Release(myComponent); 
            }
        }
    }
}
public interface IMyFactory{}
@ghost
Copy link

ghost commented Sep 19, 2017

We are thinking of deprecating this facility. Please join the discussion on #339

@ghost ghost closed this as completed Sep 19, 2017
@jonorossi
Copy link
Member

Reopening, we are looking removing the deprecated factory support facility, not the typed factory facility.

@jonorossi jonorossi reopened this Sep 20, 2017
@jonorossi
Copy link
Member

The following code snippet leads to a memory leak due to dynamically loaded assemblies that are not cleaned up.

It actually can't, the CLR does not permit unloading an assembly once it is loaded and each instance of the typed factory facility doesn't know what another instance created in the past execution of your process for that registered service.

Why are you recreating the container in your application?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants