title: Why ReleaseDC()?
body: <p>I'm developing MFC app and I at some point I got some weird Access Violation errors during idle processing loop.</p>
  
  <p>After some research I discovered that might have been caused by unreleased DCs. I have called ReleaseDC() function after every GetDC() call and errors stopped to appearing. </p>
  
  <p><strong>What I can't understand is why do I have to call ReleaseDC()?</strong> 
  . For example:</p>
  
  <pre><code>void CMainFrame::OnUpdateStatusLODLevel(CCmdUI *pCmdUI)
  {
      pCmdUI-&gt;Enable();
  
      RenderingStatistics Stats = theApp.xAM-&gt;GetRenderingStatistics();
  
      std::wstring wsText;
  
      wsText = L"LOD: ";
      wsText += std::to_wstring(Stats.uiCurrentLOD);
  
      pCmdUI-&gt;SetText(wsText.c_str());
  
      CDC* dc = m_wndStatusBar.GetDC();
  
      if (dc){
          CSize size = dc-&gt;GetTextExtent(wsText.c_str());
          m_wndStatusBar.SetPaneWidth(m_wndStatusBar.CommandToIndex(ID_STATUS_BAR_LOD_LEVEL), size.cx);
  
          ReleaseDC(dc); // without this call Access Violation errors appears
      }
  }
  </code></pre>