在TimedLock中为什么需要SuppressFinalize(tl.leakDetector)?
http://www.interact-sw.co.uk/ iangblog/2004/04/26/yetmoretimedlocking
为什么需要这一行?
System.GC.SuppressFinalize(tl.leakDetector);
我本以为不应抑制终结器来运行向剩余监视器发出警报的代码。
显然我只看调试版本。
谢谢
http://www.interact-sw.co.uk/iangblog/2004/04/26/yetmoretimedlocking
Why is this line needed?
System.GC.SuppressFinalize(tl.leakDetector);
I would have thought the finalizer should not be suppress to run the code that alerts to a left over monitor.
Obviously I'm looking at the debug version only.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
该代码的工作原理是使
leakDetector
的终结器导致 Debug.Fail,因此当该对象终结时,您会在调试器中看到问题。通过将 SuppressFinalize(..) 调用放入 Dispose() 方法中,会导致该对象仅在未调用 Dispose 时触发 Debug.Fail。
That code is working by making the finalizer for
leakDetector
cause a Debug.Fail, so you see problems in the debugger when that object is finalized.By putting the SuppressFinalize(..) call in the Dispose() method, it's causing that object to only trigger the Debug.Fail when Dispose is NOT called.