温莎城堡:我的暂态分量被垃圾收集? [英] Castle Windsor: Will my transient component be garbage collected?

查看:101
本文介绍了温莎城堡:我的暂态分量被垃圾收集?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用温莎城堡,我配置了短暂的生活方式的组成部分:

Using Castle Windsor, I have a component configured with the transient lifestyle:

<component id="publish.mapping.default"
				   service="IMyService, MyAssembly"
				   type="MyServiceImplementation, Myassembly" 
				   lifestyle="transient" />

将使用这样的:

Which will be used like this:

var service = container.Resolve<IMyService>(componentId);
// service usage ....
// service goes out of scope ...

我的问题是,将服务实例被垃圾收集后,超出范围,或将温莎城堡举行的参考?我发现<一href="http://stackoverflow.com/questions/132940/why-does-castle-windsor-hold-onto-transient-objects">this类似的问题,这意味着后者可能是这种情况 - 但检查链接贴有后,我不确定讨论是否将持有的引用,或要确保,如果它实现了对象设置IDisposable接口。我的对象并不需要被布置

My question is, will the service instance be garbage collected after it goes out of scope, or will Castle Windsor hold on to a reference ? I found this similar question, that implies that the latter might be the case - but after examining the links posted there, I am unsure whether the discussion is about holding on to the reference, or about ensuring that the object are disposed if it implements IDisposable. My objects does not need to be disposed.

如果温莎城堡持有的情况下,有没有简单的方法来prevent这个(也许配置)?

If Castle Windsor holds on to the instance, is there any easy way to prevent this (perhaps by configuration) ?

修改
看来,我需要设置的发行跟踪策略。可以在XML配置文件,该配置,还是需要在code要设置?可以释放跟踪策略来对每个组件的基础上设置?

EDIT
It seems, that I need to set the release tracking policy. Can this be configured in the xml config file, or does it need to be set in code ? Can the release tracking policy be set on a per-component basis ?

推荐答案

在默认情况下,该容器容纳引用你的对象(即使是短暂的)。

By default, the container holds a reference to your objects (even the transient ones).

不过,正如@ 苦codeR 注意到<一href="http://stackoverflow.com/questions/132940/why-does-castle-windsor-hold-onto-transient-objects">Why并城堡温莎守住瞬时对象?,您可以改变发布跟踪策略。如此看来,选择

However, as @Bittercoder notes in Why does Castle Windsor hold onto transient objects?, you can change the release tracking policy. It seems that choosing

LifecycledComponentsReleasePolicy NoTrackingReleasePolicy 应该设置你的权利了。

LifecycledComponentsReleasePolicy or NoTrackingReleasePolicy should set you right up.

这篇关于温莎城堡:我的暂态分量被垃圾收集?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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