是否有必要使用后丢弃的DbCommand?有必要、DbCommand

2023-09-02 01:42:05 作者:忘却成全

我们使用企业库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.