是否有必要使用后丢弃的DbCommand? [英] Is is necessary to dispose DbCommand after use?

查看:690
本文介绍了是否有必要使用后丢弃的DbCommand?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们使用企业库3.0访问Oracle数据库(微软Oracle客户端)。 当我不处理一个的DbCommand实例的存储过程或函数被调用后会发生什么?是否.NET自动垃圾收集的? 请注意,我们要确保事务/连接被关闭,妥善处置。

We use Enterprise Library 3.0 to access Oracle DB (microsoft oracle client). What happens when I do not dispose a DbCommand instance after a stored procedure or function is called? Does .NET automatically garbage collect them? Note that we do make sure that the transaction/connection gets closed and disposed properly.

推荐答案

这是一个重复的,但我没有时间去找到原来的。

This is a duplicate, but I don't have time to find the original.

如果它实现IDisposable,如果你创造了它,那么你需要调用Dispose就可以了。这就是为什么类的开发使其实现IDisposable。

If it implements IDisposable, and if you created it, then you need to call Dispose on it. That's why the developer of the class made it implement IDisposable.

在垃圾回收器不会在所有的IDisposable,实施对象调用Dispose。

The garbage collector does not call Dispose on all IDisposable-implementing objects.

这篇关于是否有必要使用后丢弃的DbCommand?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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