title: Implementing IDisposable C#
body: <p>I'm having a little trouble understanding the IDisposable interface</p>
  
  <p>I'm developing a Game Engine and have ran code analysis on my solution and been told to implement the IDisposable interface on my "GrapicsEngine" class, because it contains a Bitmap instance.</p>
  
  <p>Naturally, I searched the internet to learn how to do this correctly and have came up with the following code:</p>
  
  <p>Here is my class members:</p>
  
  <pre><code>private const int BITMAP_WIDTH = 4096;
  private const int BITMAP_HEIGHT = 4096;
  
  private Graphics backBuffer;
  private Bitmap bitmap;
  
  private Color clearColor;
  
  private WindowSurface surface;
  
  private GraphicsQuality quality;
  
  private Viewport viewport;
  </code></pre>
  
  <p>and here is my IDispoable region:</p>
  
  <pre><code>#region IDisposable
  
  public void Dispose()
  {
      Dispose(true);
      GC.SuppressFinalize(this);
  }
  
  protected virtual void Dispose(bool disposing)
  {
      if (disposing == true)
          ReleaseManagedResources();
  
      ReleaseUnmanagedResources();
  }
  
  private void ReleaseManagedResources()
  {
      if (bitmap != null)
          bitmap.Dispose();
      if (backBuffer != null)
          backBuffer.Dispose();
  }
  
  private void ReleaseUnmanagedResources()
  {
  
  }
  
  ~GraphicsEngine()
  {
      Dispose(false);
  }
  
  #endregion
  </code></pre>
  
  <p>Note that WindowSurface is a WinForm Panel, GraphicsQuality is an enum and Viewport contains only int values.</p>
  
  <p>So I have just a couple questions:</p>
  
  <ol>
  <li>Am I disposing of my resources properly?</li>
  <li>What resources should I dispose of in the Unmanaged resources method</li>
  <li>If I create a new class and it contains my GraphicsEngine class, should that class also implement IDisposable?</li>
  </ol>
  
  <p>Any help on this topic would be greatly appreciated.</p>