我们是否调用Dispose来处理托管对象? [英] Do we call Dispose for disposing managed objects even?

查看:68
本文介绍了我们是否调用Dispose来处理托管对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我们是否甚至为托管对象调用Dispose方法?如果仅用于非托管对象,为什么我们在Dispose结束时调用GC.SupressFinalize()方法?



谢谢,

D Apparao

Hi,

Do we call Dispose method even for managed objects? If it is for only for Unmanaged objects, why do we call GC.SupressFinalize() method at the end of Dispose?

Thanks,
D Apparao

推荐答案

您需要处置实现IDisposable的所有对象。这就是他们实现IDisposable接口的原因。



GC.SupressFinalize请求系统不为指定对象调用终结器。 (GC = 垃圾收集)SuppresFinalize只应由具有终结器的类调用。它告诉GC这个对象已经完全清理。
You need to dispose all objects that implements IDisposable. That''s why they implement IDisposable interface.

GC.SupressFinalize requests that the system not call the finalizer for the specified object. (GC=Garbage collection) SuppresFinalize should only be called by a class that has a finalizer. It''s informing the GC that this object was cleaned up fully.


它不仅仅是非托管对象,而是两个



SupressFinalize刚刚禁用了所谓的析构函数,因为我们已经手动破坏了对象
it''s not for only unmanaged object, it''s for both

SupressFinalize just disabled so called ''destructor'' because we already manualy destroyed the object


这篇关于我们是否调用Dispose来处理托管对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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