为什么温莎城堡守住短暂的对象? [英] Why does Castle Windsor hold onto transient objects?

查看:169
本文介绍了为什么温莎城堡守住短暂的对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近我发现我的应用程序似乎是吃,从来没有被释放的内存。与CLRProfiler分析后,我发现我使用的温莎城堡容器持有到对象。这些对象声明的生活方式=瞬间在配置XML属性。

Recently I noticed my application appears to be eating memory that never gets released. After profiling with CLRProfiler I've found that the Castle Windsor container I'm using is holding onto objects. These objects are declared with the lifestyle="transient" attribute in the config xml.

我发现,如果我把一个显式调用 IWindsorContainer .Release(hangingObject),它将放弃其引用。

I've found if I put an explicit call to IWindsorContainer.Release(hangingObject), that it will drop its references.

这是虽然造成了问题,我没想到,与一短暂的生活方式对象CastleWindsor将保持一个参考,并有效地创建一个泄漏。这将是一个相当普通和容易出错的任务到处插在所有适当的地方明确释放呼叫。

This is causing a problem though, I wasn't expecting that with a transient lifestyle object CastleWindsor would keep a reference and effectively create a leak. It's going to be a rather mundane and error prone task going around inserting explicit Release calls in all the appropriate places.

你见过这个问题,你有什么建议吗?怎么去解决它。

Have you seen this problem, and do you have any suggestions for how to get around it?

推荐答案

我觉得这里的答案是缺少一种关键的一点 - 这种行为是可配置出通过发布政策盒 - 退房城堡项目现场文档

I think the answers here are missing a vital point - that this behavior is configurable out of the box via release policies - check out the documentation on the castle project site here.

在很多情况下尤其是当你的容器存在宿主应用程序的生命周期,并在短暂的成分真的不需要被跟踪(因为你再处理处置这就是被注入的服务调用代码或组件),那么你可以只设置的发行策略,将 NoTrackingReleasePolicy 执行情况,并用它做。

In many scenarios especially where your container exists for the lifetime of the hosting application, and where transient components really don't need to be tracked (because you're handling disposal in your calling code or component that's been injected with the service) then you can just set the release policy to the NoTrackingReleasePolicy implementation and be done with it.

此前城堡1.0版,我相信组件负担将实行/出台 - 这将有助于缓解其中的一些问题,以及围绕注入的依赖等。

Prior to Castle v 1.0 I believe Component Burden will be implemented/introduced - which will help alleviate some of these issues as well around disposal of injected dependencies etc.

编辑:

查看以下职位的分量负担更多的讨论。

Check out the following posts for more discussion of component burden.

组件负担 - 戴维Brions

此外负担成分在的温莎集装箱的官方2.0版本

这篇关于为什么温莎城堡守住短暂的对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆