The concern is not clear. Not all types need disposal, only those implementing interface
System.IDisposable
. Also, confusingly, some types also introduce methods with the same name, not related to this interface. You really need to check up if this interface is implemented and call
System.IDisposable.Dispose
. The purpose of it can be… anything; this is just a method to do some clean-up. If you don't do this call, you can face different kinds of problems, including unmanaged memory leak. Even if an exception is thrown.
On way to make sure this is done is the
using
statement (not to be confused with
using
declaration!):
https://msdn.microsoft.com/en-us/library/aa664736%28v=vs.71%29.aspx[
^].
https://msdn.microsoft.com/en-us/library/yh598w02.aspx[
^].
—SA