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

I am having problems with the container container and Windsor entities working together, and this may be due to a problem that I introduced myself, but as a result I get terrible memory leaks.

I have an application configured using EDMX and repositories and services, and those and objectcontext are configured to perwebrequest in the Windsor configuration file that I use. However, when I look at the memory usage in the ANTS memory profiler, I see that the cache object-object is still held as a cache link, despite the confirmation that Dispose was called.

And every request of more dynamic proxies gets stuck in memory. If someone else manages to get into marijuana like this, and I can offer me advice to get out of it, it would be very helpful.

+3
source share
3 answers

I managed to find and fix the problem by changing the kernel release options for the Windsor container:

_container.Kernel.ReleasePolicy = new NoTrackingReleasePolicy();

It seems that although the Windsor container calls the dispose method for the reprogrammable components, it still hangs with reference to them, which prevents them from collecting garbage.

, , ObjectContext. , , -, , - , (, , , ), .

+4

, . "".

, .

+2

.

, _container.Release(controller) Factory:

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

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

Windsor 2.1 _container.Release(controller) .

v3.1 .

Hope this helps.

ps ANTS Memory Profiler - rescuer!

+1
source

Source: https://habr.com/ru/post/1775854/


All Articles