一次性使用和管理资源 [英] IDisposable and managed resources
问题描述
可能存在重复:
正确使用IDisposable接口
我有一个拥有托管和非托管资源的类。我正在使用IDisposable释放未管理的资源。我应该在dispose方法中释放托管资源吗?或者我可以让它发布到GC来释放托管资源? us / library / b1yfkh5e%28v = VS.100%29.aspxrel =nofollow> documentation ,你会发现这一行:
所以在你的dispose方法中,你应该处理托管也实现IDisposable的资源。如果一个对象没有实现这个,你不必处理它。
Possible Duplicate:
Proper use of the IDisposable interface
I have a class that has both managed and unmanaged resources. I am using IDisposable to release un-managed resources. Should I release managed resources in the dispose method? Or I can leave it to GC to release managed resources?
If you have a look at the following documentation you will find the line:
- Free any disposable resources a type owns in its Dispose method.
So in your dispose method you should dispose of managed resources that also implement IDisposable. If an object doesn't implement this, you don't have to dispose of it.
这篇关于一次性使用和管理资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!