Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The implementation is severely flawed. You don't truly implement <a href="http://msdn.microsoft.com/en-us/library/system.idisposable.aspx" rel="nofollow noreferrer"><code>IDisposable</code></a>, and you end up relying on the garbage collector to clean up your resources, which is a bad thing.</p> <p>Additionally, you don't even clean up those resources properly when the GC does come around (it does do it correctly, but it's by mistake that it happens).</p> <p>It is the responsibility of your class to implement <code>IDisposable</code> as you are holding onto references which implement <code>IDisposable</code>. Then, in your implementation of <a href="http://msdn.microsoft.com/en-us/library/system.idisposable.dispose.aspx" rel="nofollow noreferrer"><code>Dispose</code></a>, if you are not being GCed (it is an explicit call to <code>Dispose</code>) you are to call <code>Dispose</code> on any <code>IDisposable</code> implementations that you are holding onto.</p> <p>You check the connection status of the <code>Socket</code>, but that's not the same as calling <code>Dispose</code> on it, and you leak the resource as a result (GC eventually picks it up).</p> <p>For the guideline on how to properly implement <code>IDisposable</code>, see the section of the MSDN documentation titled "Implementing Finalize and Dispose to Clean Up Unmanaged Resources", located here:</p> <p><a href="http://msdn.microsoft.com/en-us/library/b1yfkh5e(VS.71).aspx" rel="nofollow noreferrer">http://msdn.microsoft.com/en-us/library/b1yfkh5e(VS.71).aspx</a></p> <p>I should note that I don't agree completely with these guidelines, but they are the most adopted. For my position, see here:</p> <p><a href="http://www.caspershouse.com/post/A-Better-Implementation-Pattern-for-IDisposable.aspx" rel="nofollow noreferrer">http://www.caspershouse.com/post/A-Better-Implementation-Pattern-for-IDisposable.aspx</a></p>
 

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