Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I highly recommend reading <a href="http://msdn.microsoft.com/en-us/library/498928w2(VS.80).aspx" rel="nofollow noreferrer">Cleaning Up Unmanaged Resources</a> on MSDN, it has articles touching on when to use Dispose and how to implement IDisposable correctly. Your gut instinct is mostly correct as you rarely have to implement IDisposable, unless your class uses unmanaged resources or is a container for an object that implements IDisposable.</p> <p>As to enforcing the calling of Dispose, when you properly implement the IDisposable interface you attach a finalizer which calls Dispose to catch those stragglers and deviant classes that forgot.</p> <p>Relevant articles:</p> <blockquote> <p><strong><a href="http://msdn.microsoft.com/en-us/library/fs2xkftw(VS.80).aspx" rel="nofollow noreferrer">Implementing a Dispose Method</a></strong></p> <p>Describes the implementation of the Dispose method for releasing unmanaged resources.</p> <p><strong><a href="http://msdn.microsoft.com/en-us/library/3bwa4xa9(VS.80).aspx" rel="nofollow noreferrer">Using Objects That Encapsulate Resources</a></strong></p> <p>Describes ways to ensure that the Dispose method is called, such as the C# using statement (Using in Visual Basic).</p> </blockquote> <p><em>(edit: additional information added)</em></p> <p>In your example you have <strong>SomeClass.SomeMethod</strong> which does some work, presumably with a resource. If this resource isn't a class member, you may be better served wrapping it in a <a href="http://msdn.microsoft.com/en-us/library/yh598w02(VS.80).aspx" rel="nofollow noreferrer">using-statement</a>, and forgetting about the devilish details of IDisposable.</p> <pre><code>Public Class someClass() sub someMethod Using someResource As New ResourceType( arguments ) ' no worries about IDisposable for someResource, as it is automatic End Using end sub End Class </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload