标签:简单 sse select 创建 you The col gen success
简单的说,GetDC和ReleaseDC的调用配对,CreateDC和DeleteDC的调用配对。
GetDC是从窗口获取现有的DC,而CreateDC是创建DC,所以ReleaseDC和DeleteDC的作用一个是释放,一个是销毁。
叁考:https://blog.csdn.net/business122/article/details/9612299
API原文
intReleaseDC(CDC*pDC);
Return Value
Nonzero if successful; otherwise 0.
Parameters
pDC
Identifies the device context to be released.
Remarks
Releases a device context, freeing it for use by other applications. The effect of the ReleaseDCmember function depends on the device-context type.
The application must call the ReleaseDCmember function for each call to the member function and for each call to the member function.
这里最后一句提到了
The application must call the ReleaseDCmember function for each call to the member function and for each call to the member function.
所有调用GetWindowDC和GetDC获取的DC对象必须使用ReleaseDC来释放
然后又查看了DeleteDC的API内容
CDC::DeleteDC
virtualBOOLDeleteDC();
Return Value
Nonzero if the function completed successfully; otherwise 0.
Remarks
In general, do not call this function; the destructor will do it for you. The DeleteDCmember function deletes the Windows device contexts that are associated with m_hDCin the current CDCobject. If this CDCobject is the last active device context for a given device, the device is notified and all storage and system resources used by the device are released.
An application should not call DeleteDCif objects have been selected into the device context. Objects must first be selected out of the device context before it it is deleted.
An application must not delete a device context whose handle was obtained by calling . Instead, it must call to free the device context. The and classes are provided to wrap this functionality.
The DeleteDCfunction is generally used to delete device contexts created with , , or .
看了最后一句就可以区分什么时候调用ReleaseDC了
就是GetDC或GetWindowDC获得的DC要使用ReleaseDC释放
Create得到的DC要用Delete释放
这样就不会出现内存泄露事情了
标签:简单 sse select 创建 you The col gen success
原文地址:https://www.cnblogs.com/personnel/p/14260887.html