|
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
|
|
|
|
|
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
|
|
|
|
|
Also, calling DeleteObject instead of DeleteDC.
|
|
|
|
|
We used to use boundschecker, but it din't seem to work after I upgraded to VC 6.0. (i.e. it was reporting memory leaks that weren't there)
|
|
|
|
|
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
|
|
|
|
|
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
|
|
|
|
|
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
|
|
|
|
|
I use the CWinXPButtonST class to set a cool look to my buttons.
I have a background image on my dialog and and when I using CWinXPButtonST class, and the old gray color that the buttons has is ugly. When I called the DrawTransparent() function to make it transparent the highlight event disables!
How ot make it transparent and still have the highlight event there??
MP-219
|
|
|
|
|
I haven't used CWinXPButtonST but I have used CButtonST and it sounds like maybe the button isn't flat (Highlight only works on flat buttons).. You may have to do something like m_bButton.SetFlat(TRUE);...
Hope this helps,
Rob Jones
|
|
|
|
|
Texts in titles of all windows are getting smaller and smaller when I have the fonts of controls in one window such as buttons and statics changed. I wonder how the operation on this window affulent all the windows on desktop ---- the whole OS, even after this window has exited.
my code is below:
// CDlg is derived from CDialog
BOOL CDlg::OnInitDialog(){
CDialog::OnInitDialog();
// m_button is a child button in CDlg
SetFont(&m_button, "Times New Roman", 12); // see below
m_button.SetFocus();
return false
}
CDlg::SetFont(CWnd* pWnd, char* strFont, int nSize){
CFont font;
LOGFONT logFont;
memset(&logFont, 0, sizeof(logFont));
logFont.lfHeight=-nSize;
logFont.CharSet=DEFAULT_CHARSET;
strcpy((char*)logFont.lfFaceName, strFont);
font.CreateFontIndirect(&logFont);
pWnd->SetFont(&font);
}
Maybe I should have keep the "font" variable until the dialog is ended, but the problem above still exists when I allocate memory from heap (malloc()) for "font" and "logFont". Can you change the fonts of all windows on desktop?
Tiny Flying Elephant
I love flying...
|
|
|
|
|
Make CFont a member variable of the dialog class. Fonts will then work. At least they did for me when I had this problem.
Michael Martin
Pegasystems Pty Ltd
Australia
martm@pegasystems.com
+61 413-004-018
"Don't belong. Never join. Think for yourself. Peace"
- Victor Stone
|
|
|
|
|
Yes, the font variable lifetime should be longer. Just make it a data member of CYourDialog - no need for malloc or new.
LOGFONT is needed only to call CreateFontIndirect. It can be a local variable.
Have no idea why your app changes the systemwide settings - does this happen only if you call CWnd::SetFont?
Tomasz Sowinski -- http://www.shooltz.com
|
|
|
|
|
I have an application that shows a splash screen for 5 seconds, the splash screen is deleted and a dialog box should be shown. The problem I had was that the dialog box would be behind everything else (the edit box inside the dialog would still have focus, which is correct). To solve this, in the OnInitDialog of the dialog I set the window position and size etc and set the first parameter to wndTopMost. This worked up to a point. The dialog is now on top and the cursor is flashing in the edit box where it should, BUT the box itself still doesn't have focus and you have to click on it before you can type in the edit box. Any ideas how to rectify this?
Thanks in advance for any help,
Nick
|
|
|
|
|
This is probably a problem with splash screen which is disabling your dialog window. Check if splash calls EnableWindow.
Tomasz Sowinski -- http://www.shooltz.com
|
|
|
|
|
I was actually using the splash class wrongly and putting a line of code in the wrong place (doh), thanks for the help though,
Nick
|
|
|
|
|
I noticed in various program loops that allocating a buffer with the new operator didn't seem to work each time. I mean it did work but partially, I sometime have partially allocated buffers (?).
This:
char* pBuf = new char[iVariable];
is not safe. When iVariable is a constant, like MAX_PATH it always succeed but not when it has a dynamic value.
I admit, I seldom test if the allocation succeded or not but the buffer is always allocated but not on the entire sequence (?). Maybe doesn't the new operator allocate contiguous memory blocks and then a pointer operation (pBuf++) is not safe ?
Then, I wonder when I should use malloc instead of new to get sure the buffer is allocated ?
Yarp
|
|
|
|
|
malloc() is for C programs, new is for C++ programs. You can never be sure that your allocation succeeds, always check the result! If the allocation succeeds, the memory block is always contiguous and the size you requested.
|
|
|
|
|
malloc() is for C programs, new is for C++ programs.
This is too strict. One can safely use malloc/free in C++ program. Just don't mix malloc with delete and new wih free
- what was allocated with new should be deallocated with delete, malloc() should be accompanied by free().
Tomasz Sowinski -- http://www.shooltz.com
|
|
|
|
|
char* pBuf = new char[iVariable];
is safe, at least when iVariable is correctly initialized. If iVariable contains bogus bits, the buffer size may be too large to fit on the heap. In such case, operator new fails and returns NULL on VC6 or throws bad_alloc exception on standard-conforming compilers.
the buffer is always allocated but not on the entire sequence (?).
I don't understand what do you mean.
Maybe doesn't the new operator allocate contiguous memory blocks
It allocates contiguos block of size passed in iVariable.
Tomasz Sowinski -- http://www.shooltz.com
|
|
|
|
|
Hi, thank you all for replying.
the buffer is always allocated but not on the entire sequence (?).
I mean that I was reading a file buffer and I read the beginning of the buffer but the buffer is empty before the end of it, so I suppose it was partially initialized.
Yarp
|
|
|
|
|
I found out the problem: iVariable ;((
I used the size of another -smaller- disk file (i used it to load a file buffer in memory). The "smaller" makes all difference and actually did the partial buffer load that I noticed.
Anyway, I'm now sure that new and malloc have the same usage and that they both create contiguous memory buffer.
Sorry and thanks )
Yarp
|
|
|
|