title: How to correct the GDI resource leakage?
body: <p>I found out that after FillRgn() Windows GDI API function, the GDI object used in this function is somehow "stuck" somewhere in the internal system maps and won't delete properly: calling DeleteObject() on the object returns successfully, but the number of GDI objects for the process does not decrement. Here is the code:</p>
  
  <pre><code>void gditest()
  {
      HBRUSH h = CreateSolidBrush(RGB(255, 237, 5));
      HRGN rgn = CreateRectRgn(0, 100, 100, 0);
      FillRgn(g_DC, rgn, h);
  
      int before = GetGuiResources(GetCurrentProcess(), GR_GDIOBJECTS);
      SelectObject(g_DC, GetStockObject(WHITE_BRUSH));
      int rs = DeleteObject( h );
      if ( !rs )
          throw;
      int after = GetGuiResources(GetCurrentProcess(), GR_GDIOBJECTS);
  }
  </code></pre>
  
  <p>The code demonstrates that after deleting the HBRUSH handle variables 'before' and 'after' are equal; g_DC is the main window HDC.</p>
  
  <p>How to delete the 'h' so that the number of GDI objects were decrementing?</p>