Autofac, Owin and memory leaks. Is autofac leaking with owin?

梦想的初衷 提交于 2019-12-10 23:39:38

问题


Recently I realized there is a leak in my Web API application based on Owin and Autofac. The leak is not permanent but memory kept longer than per request. Here's the deal:

1-) By default Web API uses buffered responses and the runtime keeps OverlappedData structure up to 40 instances as an object pool even after the response is returned. (For performance reasons I guess)

2-) Each OverlappedData structure keeps the OwinContext alive (only 40 at a time probably for pooling)

3-) Because OwinContext is alive, the associated Autofac container per request scope is kept alive though the container itself is disposed.

4-) Even if Autofac container is disposed, it is keeping the objects in its sharedInstances dictionary.

Hence the memory leak. A workaround is to use streaming instead of buffering and then there is no OverlappedData. But I am curious about another solution.

Another weird thing is if an Autofac container is disposed it is still keeping the data in its dictionary. It should set the dictionary to null instead! Any ideas ?

来源:https://stackoverflow.com/questions/40290851/autofac-owin-and-memory-leaks-is-autofac-leaking-with-owin

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