Need tools / techniques for tracing GDI leakage
-
I agree - not having an evaluation copy to play with is pants! Here are some classic leak examples: void CMyView::OnDraw(CDC* pDC) { CFont font; // Create a font font.CreatePointFont(120, _T("Arial"), pDC); // Select the font into the DC pDC->SelectObject(&font); // Draw pDC->TextOut(0, 0, _T("Leak!")); // The original font isn't selected back into the DC // and the font we created is about to be deleted. // This will soon deprive you of resources (Win9x especially) } void CMyView::DrawSomething() { // Get a DC CDC* pDC = GetDC(); // Draw pDC->TextOut(0, 0, _T("Leak!")); // You must call ReleaseDC, else this will leak! }
Hi, I can see why these examples would cause leakage, and in looking through my source files - I'm not guilty of either of them (mores he pity, cos then at least i would have found some leaks ... Jase Jase ------------------------------------------------------------------------------------------------------------------------------------------------------------------- View your digital photos and images with ease using the ultimate desktop image manager for Microsoft Windows Download your free copy of SlideShow Desktop today from http://www.slideshowdesktop.com
-
Hi, I can see why these examples would cause leakage, and in looking through my source files - I'm not guilty of either of them (mores he pity, cos then at least i would have found some leaks ... Jase Jase ------------------------------------------------------------------------------------------------------------------------------------------------------------------- View your digital photos and images with ease using the ultimate desktop image manager for Microsoft Windows Download your free copy of SlideShow Desktop today from http://www.slideshowdesktop.com
-
I am more than happy to look at your code if you like - I quite enjoy looking for leaks! Plus I have a pucker copy of BC I can run it through ... :)
Thanks for your kind offer. However, my source is for a commercial product so i can't show you the code ... Jase ------------------------------------------------------------------------------------------------------------------------------------------------------------------- View your digital photos and images with ease using the ultimate desktop image manager for Microsoft Windows Download your free copy of SlideShow Desktop today from http://www.slideshowdesktop.com
-
Bounds checker is probably the best tool for tracking GDI leaks, but it ain't cheap. For memory leaks I would recommend PurifyNT, but, again, it's expensive. In my experience of Windows programming (10 years now) the most common leaks are: * Deleting pens, brushes or fonts that are still selected in the DC. * Calling GetDC without a corresponding ReleaseDC. Regards.
-
Hi, I need to find a tool or learn some techniques that can help me trace GDI leakage. I've found some tools on MSDN which work for Windows Me and 2000, but i also need to check on NT4. Besides, the tools i found on MSDN weren't very good anyway. They reported massively spiralling leakages for palletes and regions and bitmaps when i'm not creating any! Surely to leak, i would have to create and forget to destroy. So those tools may justfifably have been telling me about leaks - but definately they were incorrectly identifying the resource. And they didn't help you find the code. Any ideas please ? Jase ------------------------------------------------------------------------------------------------------------------------------------------------------------------- View your digital photos and images with ease using the ultimate desktop image manager for Microsoft Windows Download your free copy of SlideShow Desktop today from http://www.slideshowdesktop.com
MSDN mag ran an article in the last 12-18 months and not in the last 6, which was a program that showed you the bitmaps/pens/etc that had not been deleted. It rocked, if you cannot find it LMK and I'll dig it up. Also, W2000 makes you work pretty hard to leak GDI memory, because it cleans up after you. This I know from bitter experience. Christian As I learn the innermost secrets of the around me, they reward me in many ways to keep quiet. Men with pierced ears are better prepared for marriage. They've experienced pain and bought Jewellery.
-
MSDN mag ran an article in the last 12-18 months and not in the last 6, which was a program that showed you the bitmaps/pens/etc that had not been deleted. It rocked, if you cannot find it LMK and I'll dig it up. Also, W2000 makes you work pretty hard to leak GDI memory, because it cleans up after you. This I know from bitter experience. Christian As I learn the innermost secrets of the around me, they reward me in many ways to keep quiet. Men with pierced ears are better prepared for marriage. They've experienced pain and bought Jewellery.
I think the tool you mentioned is the tool i mentioned earlier. It is only 95/98 , and you're right - it shows the pensd , palletes and fonts that you are leaking. And it does indeed display lots of them! Only i don't use any, so its not my app thats leaking them :( From the outset, it looks pretty good. But in truth, it doesn't reflect the state of my application one iota. It's called GDIUsage - is this the one ? You have to build it from source - available from MSJ online. Jase ------------------------------------------------------------------------------------------------------------------------------------------------------------------- View your digital photos and images with ease using the ultimate desktop image manager for Microsoft Windows Download your free copy of SlideShow Desktop today from http://www.slideshowdesktop.com
-
I am more than happy to look at your code if you like - I quite enjoy looking for leaks! Plus I have a pucker copy of BC I can run it through ... :)
Out of interest - how did you get your hands on a copy. I've looked on their website and it doesn't even give a price. It sems you have to go through a salesman / vendor in order to get a copy. And did you then enter a registration code to it ? (that is, it was 'unlockable') ? Jase ------------------------------------------------------------------------------------------------------------------------------------------------------------------- View your digital photos and images with ease using the ultimate desktop image manager for Microsoft Windows Download your free copy of SlideShow Desktop today from http://www.slideshowdesktop.com
-
I think the tool you mentioned is the tool i mentioned earlier. It is only 95/98 , and you're right - it shows the pensd , palletes and fonts that you are leaking. And it does indeed display lots of them! Only i don't use any, so its not my app thats leaking them :( From the outset, it looks pretty good. But in truth, it doesn't reflect the state of my application one iota. It's called GDIUsage - is this the one ? You have to build it from source - available from MSJ online. Jase ------------------------------------------------------------------------------------------------------------------------------------------------------------------- View your digital photos and images with ease using the ultimate desktop image manager for Microsoft Windows Download your free copy of SlideShow Desktop today from http://www.slideshowdesktop.com
That sounds like it. I dunno about NT 4, but I can tell you that code that runs fine under W2000 will crash W98 for GDI leaks in seconds. It's possible NT4 protects itself in a similar way, but the reason the code only ran under 95/98 (and I guess ME ) is that the handles to the objects were all global. It shows you what exists on the system, not what has leaked, that is why it fills up. You look to see if the list is growing a lot by taking snapshots and seeing what is different between two points in time, and if there is a lot there you should have deleted. Christian As I learn the innermost secrets of the around me, they reward me in many ways to keep quiet. Men with pierced ears are better prepared for marriage. They've experienced pain and bought Jewellery.
-
Bounds checker is probably the best tool for tracking GDI leaks, but it ain't cheap. For memory leaks I would recommend PurifyNT, but, again, it's expensive. In my experience of Windows programming (10 years now) the most common leaks are: * Deleting pens, brushes or fonts that are still selected in the DC. * Calling GetDC without a corresponding ReleaseDC. Regards.
-
That sounds like it. I dunno about NT 4, but I can tell you that code that runs fine under W2000 will crash W98 for GDI leaks in seconds. It's possible NT4 protects itself in a similar way, but the reason the code only ran under 95/98 (and I guess ME ) is that the handles to the objects were all global. It shows you what exists on the system, not what has leaked, that is why it fills up. You look to see if the list is growing a lot by taking snapshots and seeing what is different between two points in time, and if there is a lot there you should have deleted. Christian As I learn the innermost secrets of the around me, they reward me in many ways to keep quiet. Men with pierced ears are better prepared for marriage. They've experienced pain and bought Jewellery.
Hi, Thanks for your reply. I have managed to trace the problem that i had (thanks to an evaluation copy of Bounds Checker) - it was all thanks to a couple of HKEY's which i had forgot to do a RegClose() on. Just a silly mistake really (but aren't they all?). Still, it begs the question - why did the gdi tool we are discussing show me lots of fonts , pallettes and regions when i took the comparison snapshots? I had no other program running at the time, so these resources weren't being created by any other application. Is it possible that it could mistake HKEY's (and whatever may be internally allocated when opening a registry key) for GDI resources , and then point me at some bogus resources ? Are registry keys treated similarly to file's / sockets ? i.e. there are a physical limit to the number of open files you can have - is the same true for reg keys ? Would this also make sense of all the 'A resource you requested was unavailable' msg boxes that popped up when my 'resources' were running low. Am i likely to get this error if it was in fact due to reg keys ? damn, there's so much to learn. Jase ------------------------------------------------------------------------------------------------------------------------------------------------------------------- View your digital photos and images with ease using the ultimate desktop image manager for Microsoft Windows Download your free copy of SlideShow Desktop today from http://www.slideshowdesktop.com
-
Hi, Thanks for your reply. I have managed to trace the problem that i had (thanks to an evaluation copy of Bounds Checker) - it was all thanks to a couple of HKEY's which i had forgot to do a RegClose() on. Just a silly mistake really (but aren't they all?). Still, it begs the question - why did the gdi tool we are discussing show me lots of fonts , pallettes and regions when i took the comparison snapshots? I had no other program running at the time, so these resources weren't being created by any other application. Is it possible that it could mistake HKEY's (and whatever may be internally allocated when opening a registry key) for GDI resources , and then point me at some bogus resources ? Are registry keys treated similarly to file's / sockets ? i.e. there are a physical limit to the number of open files you can have - is the same true for reg keys ? Would this also make sense of all the 'A resource you requested was unavailable' msg boxes that popped up when my 'resources' were running low. Am i likely to get this error if it was in fact due to reg keys ? damn, there's so much to learn. Jase ------------------------------------------------------------------------------------------------------------------------------------------------------------------- View your digital photos and images with ease using the ultimate desktop image manager for Microsoft Windows Download your free copy of SlideShow Desktop today from http://www.slideshowdesktop.com
How did you manage to get an evaluation of Boundschecker? James Spibey I love the word naked, it's brilliant isn't it, 'naked'. When I was a kid I used to write the word naked on a bit of paper hundreds of times and rub my face in it - Jeff, Coupling, BBC2