Memory Leaks when using Entity Framework and Windsor in an ASP.NET MVC application

蹲街弑〆低调 提交于 2019-12-03 17:14:27

I've managed to track down and resolve the problem by changing the release settings on the kernal for the windsor container to:

_container.Kernel.ReleasePolicy = new NoTrackingReleasePolicy();

It seems although the windsor container calls the dispose method of perwebrequest components it still hangs on to a reference of them which prevents them being garbage collected.

In this case the object it was holding a reference to was of type ObjectContext. Unfortunately despite disposing of this object the all the dynamic proxies cached in this object still remain effectively meaning that a copy of my database (or at least the parts I was accessing) was being added to memory each request causing it to ramp up.

You are probably not disposing objects correctly. Try using "Using" blocks.

Cannot say much more without seeing the code.

I had the same problem.

After investigation it seemed that I was missing a call to _container.Release(controller) in my Controller Factory:

    public override void ReleaseController(IController controller)
    {
        _container.Release(controller);

        var disposable = controller as IDisposable;
        if (disposable != null)
        {
            disposable.Dispose();
        }
    }

However, I was also using Windsor 2.1 and adding _container.Release(controller) did not do anything for me.

After updating to v3.1 it seems to work.

Hope this helps.

p.s. ANTS Memory Profiler - lifesaver!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!