在 ASP.NET MVC 应用程序中使用实体框架和 Windsor 时出现内存泄漏
我无法让温莎容器和实体框架一起工作,这可能是由于我自己介绍的一个问题,但最终结果是我遇到了严重的内存泄漏。
我的应用程序设置了 EDMX、存储库和服务,这些内容和 objectcontext 在我使用的温莎配置文件中设置为 perwebrequest。然而,当我查看 ANTS 内存分析器中的内存使用情况时,我发现尽管确认已调用 Dispose,但对象上下文缓存仍被保留为缓存的引用。
每个请求都会有更多的动态代理被困在内存中。如果其他人设法让自己陷入这样的困境,并能为我提供摆脱困境的建议,我将不胜感激。
I'm having trouble getting the windsor container and entity framework working together and it may be due to a problem I've introduced myself but the net result is that I'm getting a terrible memory leaks caused.
I have my application set up with an EDMX and Repositories and Services and those and the objectcontext are set to perwebrequest in the windsor configuration file I use. However when I look at the memory usage in ANTS memory profiler I see that the object context cache is still being held onto as a reference with the cache despite confirming that Dispose has been called.
And each request more dynamic proxies are getting stuck in memory. If anyone else has managed to get themselves in a pickle like this and can offer me advice to get out of it, it would be greatly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我已经通过将 Windsor 容器的内核上的发布设置更改为:
似乎虽然 Windsor 容器调用了 perwebrequest 组件的 dispose 方法,但它仍然挂在它们的引用上,从而阻止了它们正在被垃圾收集。
在本例中,它所持有的引用的对象是 ObjectContext 类型。不幸的是,尽管处置了该对象,但该对象中缓存的所有动态代理仍然有效,这意味着我的数据库的副本(或至少是我正在访问的部分)被添加到内存中,每个请求都会导致其加速。
I've managed to track down and resolve the problem by changing the release settings on the kernal for the windsor container to:
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.
我也有同样的问题。
经过调查,我似乎在控制器工厂中错过了对 _container.Release(controller) 的调用:
但是,我也在使用 Windsor 2.1 并且添加 _container.Release(controller) 对我没有任何作用。
更新到 v3.1 后似乎可以工作了。
希望这有帮助。
ps ANTS 内存分析器 - 救星!
I had the same problem.
After investigation it seemed that I was missing a call to _container.Release(controller) in my Controller Factory:
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!