title: Understanding disposable objects
body: <p>I've looked in SO about a question like this one, and even that I've found quite a few, any of those threw any light into this matter for me.</p>
  
  <p>Let's assume I have this code:</p>
  
  <pre class="lang-cs prettyprint-override"><code>public class SuperObject : IDisposable
  {
      public void Dispose()
      {
          Dispose(true);
          GC.SuppressFinalize(this);
      }
  
      protected virtual void Dispose(bool disposing) { }
  }
  </code></pre>
  
  <ul>
  <li>Do I need the <code>protected virtual void Dispose(bool)</code> on <code>SuperObject</code>? Since there is really nothing to dispose there.</li>
  </ul>
  
  <pre class="lang-cs prettyprint-override"><code>public interface ICustom : IDisposable { }
  </code></pre>
  
  <pre class="lang-cs prettyprint-override"><code>public class Custom : ICustom
  {
      public SuperObject Super { get; protected set; }
  
      public Custom()
      {
          Super = new SuperObject();
      }
  
      public void Dispose()
      {
          Dispose(true);
          GC.SuppressFinalize(this);
      }
  
      public virtual void Dispose(bool disposing)
      {
          if (!disposing) return;
  
          if (Super != null)
              Super.Dispose();
      }
  }
  </code></pre>
  
  <pre class="lang-cs prettyprint-override"><code>public class Foo
  {
      public Foo()
      {
          using (var c = new Custom())
          {
              //do magic with c
          }
      }
  }
  </code></pre>
  
  <p>Now what happens if I want/need/try to use <code>Custom</code> on a class like <code>System.Web.Mvc.Controller</code> which already implements and has implemented IDisposable?</p>
  
  <pre class="lang-cs prettyprint-override"><code>public class Moo : Controller
  {
      Custom c;
  
      public Moo()
      {
          c = new Custom();
      }
  
      // Use c throughout this class        
  }
  </code></pre>
  
  <p><strong>How to properly dispose <code>c</code> in <code>Moo</code>?</strong></p>