You are not logged in. You can browse in the PowerBASIC Community, but you must click Login (top right) before you can post. If this is your first visit, check out the FAQ or Sign Up.
The best "rule" is to store the original object handle (brush, pen, etc) at the 1st selection, and just before deleteing or releasing the DC, reselect the original object(s).
Locating which GDI object is leaking is not always easy, but ignoring API return codes is a sure-fire way of overlooking the real cause of a leak.
The leak was happening because I was deleting the DC and it had a pen still attached to it, because DeleteObject(m_hPen) was failing due to the pen still being attached to the DC.
So, aways replace the Pen with a stock object and then delete the Pen. . . I did not know that you had to do that.
Thanks Lance!
Tim
[This message has been edited by Tim Wisseman (edited June 12, 2000).]
Leave a comment:
Guest replied
You are right that last line fails, it returns a zero. The SelectObject returns a handle and the DeleteDC and first DeleteDC returns a 1 so they are working.
It must be in the drawing code. . .
[This message has been edited by Tim Wisseman (edited June 12, 2000).]
Then hBmp would be equal to m_hBmp, so the last two calls are performing an identical task, and hence the 1st should success, but the second has to fail (as the same handle was just released by the 1st DeleteObject() call).
Therefore the 1st question is this: what are the return results from these API's (DeleteObject(), DeleteDC(), etc).
If they are returning *valid* return values to indicate that they were successful (and at least one of these you listed should not work as I mentioned above), then the problem is somewhere else in your code that you have no given us. FOr example, maybe you arew drawing on the memory bitmap, and you are attempting to release a pen or brush that is still selected into the DC? If you verify the return result from every API, you'll find the cause (provided you match the destruction of every GDI object to it's creation).
The following series of commands are leaking a little GDI memory every time they are called. Something is not being deleted. Any ideas as to how to correctly delete the DC and bitmaps?
' Create hidden surface, m_ctrlhDC never changes through the
' life of the program
m_hDC = CreateCompatibleDC(m_ctrlhDC)
'To draw to the hidden surface need to create a bitmap
m_hBMP = CreateCompatibleBitmap(m_ctrlhDC, m_ctrlWidth, m_ctrlHeight)
'Attach Bitmap to hidden surface
m_OldhBMP = SelectObject(m_hDC, m_hBMP)
Local hBmp As Long
'First deselect bitmap
hBmp = SelectObject(m_hDC, m_OldhBMP)
We process personal data about users of our site, through the use of cookies and other technologies, to deliver our services, and to analyze site activity. For additional details, refer to our Privacy Policy.
By clicking "I AGREE" below, you agree to our Privacy Policy and our personal data processing and cookie practices as described therein. You also acknowledge that this forum may be hosted outside your country and you consent to the collection, storage, and processing of your data in the country where this forum is hosted.
Leave a comment: