title: C++ double buffer and memory
body: <p>Ok so my double buffer works fine but it seems that it use a lot of memory.</p>
  
  <p>i know that double buffer should store a copy of the ellipse I'm drawing than paint it on the screen but it after that it deletes the copy and makes new copy but it doesn't seem to delete it 
  here is my code</p>
  
  <pre><code>hdc=GetDC(hWnd);
  HDC memDC=CreateCompatibleDC(hdc);
  HBITMAP hMemMap=CreateCompatibleBitmap(hdc, 300, 300);
  HBITMAP hOldMap=(HBITMAP)SelectObject(memDC, hMemMap);
  
  // Drawing
  Graphics draw(memDC);
  draw.FillRectangle(&amp;green, 0, 0, 300, 25);
  Font font(&amp;fontfamily, 14, 0, UnitPixel);
  PointF p1(180.0f, 4.0f);
  PointF p2(30.0f, 4.0f);
  draw.DrawString(level, -1, &amp;font, p2, &amp;blue);
  draw.DrawString(str, -1, &amp;font, p1, &amp;blue);
  draw.FillEllipse(&amp;red, ball1.Ex, ball1.Ey, 25, 25);
  draw.FillEllipse(&amp;red, ball2.Ex, ball2.Ey, 25, 25);
  draw.FillEllipse(&amp;red, ball3.Ex, ball3.Ey, 25, 25);
  draw.FillEllipse(&amp;red, ball4.Ex, ball4.Ey, 25, 25);
  draw.FillEllipse(&amp;red, ball5.Ex, ball5.Ey, 25, 25);
  draw.FillEllipse(&amp;red, ball6.Ex, ball6.Ey, 25, 25);
  draw.FillEllipse(&amp;red, ball7.Ex, ball7.Ey, 25, 25);
  draw.FillEllipse(&amp;red, ball8.Ex, ball8.Ey, 25, 25);
  draw.FillEllipse(&amp;red, ball9.Ex, ball9.Ey, 25, 25);
  draw.FillEllipse(&amp;red, ball10.Ex, ball10.Ey, 25, 25);
  BitBlt(hdc, 0, 0, 300, 300, memDC, 0, 0, SRCCOPY);
  SelectObject(memDC, hOldMap);
  DeleteObject(hMemMap);
  DeleteDC(memDC);
  </code></pre>
  
  <p>Any ideas?</p>