顽固的自定义对象 [英] obstinate custom object
问题描述
专家,
在一个应用程序中,我有一个包含 System.Timers.Timer [ ^ ]。该对象由 Assembly.CreateInstance(string) [<}实例化。 a href =http://msdn.microsoft.com/en-us/library/dex1ss7c(v=vs.80).aspx\"target =_ blanktitle =New Window> ^ ],读取了一些属性,然后就不再需要对象。
直到最近,我发现没有问题。新东西是这个带有计时器的对象。在此对象预期寿命之后很长时间,它会不断流逝(因此执行方法,它不应该)。
我可以做些什么来摆脱对象之后已阅读所有相关属性?
正在实施 IDisposable [ ^ ]接口的方式去?
Hi experts,
in an application, I have an object that contains a System.Timers.Timer[^]. The object is instantiated by Assembly.CreateInstance(string)[^], some properties are read and then there's no further need for the object.
Until recently, I observed no problem. The new thing is this object with a timer. Long after this objects intended lifespan, it keeps elapsing (and therefore executing methods, which it shouldn't).
What can I do to get rid of the object after all relevant properties have been read?
Is implementing the IDisposable[^] interface the way to go?
推荐答案
作为 Sushil Mate [ ^ ]已经在他的评论 [ ^ ]上方。完成对象后禁用计时器。
如果您不确定对象在超出范围后仍然存活的原因。您会发现调试/分析堆是一项富有洞察力的工作。当前最先进的分析器通常具有板载这些内存/堆分析器。
问候,
- 曼弗雷德
As Sushil Mate[^] already said in his comment[^] above. Disable the timer when you're done with the object.
If you're unsure about why the object is still alive even after it has gone out of scope. You'll find debugging/analyzing the heap an insightful endeavor. Current "state of the art" profilers usually have of these memory/heap analyzers "on board".
Regards,
— Manfred
这篇关于顽固的自定义对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!