title: C# how to implement Dispose method
body: <p>I need some advice on the implementation of the <code>Dispose</code> method.</p>
  
  <p>In our application the user designs their own UI.  I have a preview window that shows what the UI is going to look like.  All object drawn in this UI ultimately derive from a common base class ScreenObject.  My preview manager contain a single object reference to a ScreenGrid which is the grid object for the entire preview area.</p>
  
  <p><strong>Question #1</strong></p>
  
  <p>Some of my derived screen classes hold onto unmanaged resources, such as a database connection, bitmap image and a <code>WebBrowser</code> control.  These classes need to dispose of these objects.  I created a virtual <code>Dispose</code> method in the base <code>ScreenObject</code> base class and then implemented an override <code>Dispose</code> method in each of the derived classes that hold onto unmanaged resources.  However, right now I just created a method called <code>Dispose</code>, I am not implementing <code>IDisposable</code>.  Should I implement <code>IDisposable</code>?  If so how do I implement it?</p>
  
  <ul>
  <li>Just on the derived classes that have unmanaged resources</li>
  <li>The base class and derived classes that have unmanaged resources <em>OR</em></li>
  <li>The base class and all derived classes including those that do not have unmanaged resources</li>
  </ul>
  
  <p>Is it wrong to put a virtual <code>Dispose</code> method in a base class that doesn't have unmanaged resources so that you can take advantage of polymorphism?</p>
  
  <p><strong>Question #2</strong></p>
  
  <p>In reading about the <code>Dispose</code> method and the <code>IDisposable</code> interface Microsoft states that the disposing object should only call the <code>Dispose</code> method for its parent. The parent will call it for its parent and so on. To me this seems backwards. I may want to dispose of a child but keep its parent around.</p>
  
  <p>I would think it should be the other way around, an object being disposed should dispose of its children.  The children should then dispose of their children and so on.</p>
  
  <p>Am I wrong here or am I missing something?</p>