Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does this class implement IDisposable if it doesn't have a Dispose method?

FtpWebResponse implements IDisposable, but it doesn't have a Dispose method. How is that possible?

like image 559
MCS Avatar asked Jun 25 '10 14:06

MCS


People also ask

What happens if you dont Dispose IDisposable?

IDisposable is usually used when a class has some expensive or unmanaged resources allocated which need to be released after their usage. Not disposing an object can lead to memory leaks.

How do you Dispose of IDisposable?

If you don't use using , then it's up to you (the calling code) to dispose of your object by explicitely calling Dispose().

How do you know if a class implements IDisposable?

If a type implements the IDisposable interface, you should always call the Dispose method on an instance of the class when you are done using it. The presence of IDisposable indicates that the class has some resources that can be released prior to garbage collection.

Why we need to implement Dispose method while we have option to implement destructor?

It is always recommended to use Dispose method to clean unmanaged resources. You should not implement the Finalize method until it is extremely necessary. At runtime C#, C++ destructors are automatically converted to Finalize method.


1 Answers

Its implemented in the base class WebResponse, see http://msdn.microsoft.com/en-us/library/system.net.webresponse_methods.aspx

like image 138
blu Avatar answered Sep 21 '22 16:09

blu