DataSet调用Dispose必须吗
2016-04-26 19:33
381 查看
DataSet是一个离线托管Object
Dispose() 是的典型被调用来释放非托管资源,例如 文件指针,流等。大部分情况,像类也会为它们暴露一个更合适的Close()方法。
DataSet类是继承自MarshalByValueComponent. 它作为组件实现了IDisposable接口。Dispose()方法默认的任务是从父容器移除组件。但这个方法没有在System.Data.DataSet类中覆写。并且DataSet没有父容器。所以使用Dispose()方法没意义。
http://stackoverflow.com/questions/913228/should-i-dispose-dataset-and-datatable http://burnignorance.com/net-development-tips/is-it-necessary-to-call-dispose-on-a-dataset/
Dispose() 是的典型被调用来释放非托管资源,例如 文件指针,流等。大部分情况,像类也会为它们暴露一个更合适的Close()方法。
DataSet类是继承自MarshalByValueComponent. 它作为组件实现了IDisposable接口。Dispose()方法默认的任务是从父容器移除组件。但这个方法没有在System.Data.DataSet类中覆写。并且DataSet没有父容器。所以使用Dispose()方法没意义。
http://stackoverflow.com/questions/913228/should-i-dispose-dataset-and-datatable http://burnignorance.com/net-development-tips/is-it-necessary-to-call-dispose-on-a-dataset/
Dataset is a disconnected managed object. Dispose() is typically called to release unmanaged resources such as file-pointers, streams etc. In most cases, such classes also expose a Close()method that is more appropriate for them. Dataset class is being inherited from the MarshalByValueComponent. This implements the IDisposable interface as it is a component. The default task of the Dispose() method is to remove the component from the parent container. But this method is not overridden in the System.Data.Dataset class. Also in case of Dataset there is no parent container. So use of Dispose()method has no more significance. |
Conclusion: It is not necessary to call Dispose() on Datasets. Calling the Clear() can also be appropriate. |
相关文章推荐
- 编码识别工具:hash-identifier
- Flex,Flash,AS3,AIR的关系和区别(转载)
- 4.20作业
- 20160426 Python视频教程
- HDU 5656 CA Loves GCD
- C++第四次作业
- html5+开发移动app
- Calendar时间操作
- java 面向对象编程(OOP)-个人理解
- 为什么 Python 不支持函数重载?
- vi编辑器的使用方法
- iOS Crash文件的解析(一)
- mysql修改编码格式
- 第六次作业
- ZOJ 3938-Defuse the Bomb【模拟,题看着挺长】(2016浙江省大学生程序设计竞赛)
- 【框架】RefreshListView下拉刷新
- 公式加括号的所有可能
- 给大家共享一个个人认为非常好的动画网站
- keras代码阅读-Activition层
- 设计模式:访问者模式(Visitor)