Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The primary use of IDisposable interface [duplicate]

Possible Duplicate:
Proper use of the IDisposable interface

"IDisposable Interface" article tells:

The primary use of this interface is to release unmanaged resources

Why? Why only unmanaged?

Whole my life I thought its PRIMIRALY use is to release ANY resources: managed (connections to DBs, services proxies, etc) and unmanaged (if they are used in application).

P.S.

I believe there are already questions on this topic, but can't find them.

like image 847
Budda Avatar asked Jun 23 '11 02:06

Budda


1 Answers

The underlying connections to db's are not managed, as are file handles and a number of other low-level o/s objects. They are unmanaged. Implementing an IDisposable interface implies that you are not just relying on the garbage collector to release those resources; but you are closing those resources using what ever low-level API that you have available.

Also, I think Eric Lippert's answer (2nd one down) to a similar question is a very good explanation on why you would use IDisposable.

like image 145
David Hoerster Avatar answered Oct 23 '22 21:10

David Hoerster