| |
|
What is IDisposable interface in .NET?
IDisposable interface - We implement this interface to a class when we have to work with
unmanaged types. For example, an IntPtr member representing an operating system's file handler
is actually unmanaged, and in order to destroy it, we make use of the Dispose method by
implementing the IDisposable interface. In this case, we override the Finalize method.
Note that we make use of Dispose method on those objects which have an uncertain life period,
and thus the garbage collector does not finalize them automatically.
We also make use of Dispose method while working with managed code, for example, an object os
System.IO.FileStream may have an uncertain life, and in order to dispose it, we use the
dispose method. Such types of objects are not accessed by the Garbage Collector's Finalizer.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
| |