Skip to main content
GameDev.net gamedev.net
🔒 Locked

SetDlgItemText memory leak?

Started by Morpheus011 Dec 28, 2006 at 10:35 AM 11 replies 3k views
Original Post
Morpheus011
Morpheus011
We are working on an MFC based tool (I know, I know, MFC is outdated and ugly) and we were looking at Windows Task Manager and have been noticing a consistent memory leak with the tool. We have commented out all of our rendering and logic code, and we still are leaking about 4K a second, and about 8K every other second. We have narrowed it down to a SetDlgItemText() call, which when commented out takes away the 8K leak. We have been using CStrings, but even have attempted to use a const string literal like "HELLO" and we still get a leak. So, our assumptions are that either SetDlgItemText() has a known issue (which isn't documented either in MSDN or across the web according to Google) or Windows Task Manager is a liar, or we are a couple of idiots and are using SetDlgItemText() incorrectly. I brought out some old MFC apps to see if the same thing was happening and oddly enough it was. Anyone else run into this issue before? We could use some insight, thanks.
asm_fsm
asm_fsm
SetDlgItemText IS documented.

If you're having issues with it, it's probably somewhere else in your code, or else there would be massive out cry about it on the internet, as it's probably one of the most commonly called functions in win32 applications programming.

Maybe your sending it a string that isn't null terminated?
LessBread
LessBread
Are you referring to CWnd::SetDlgItemText or the api function SetDlgItemText?

The remarks for the api function says: The SetDlgItemText function sends a WM_SETTEXT message to the specified control. So maybe you can roll your own version to bypass SetDlgItemText.

Have you searched google groups? SetDlgItemText memory leak
"I thought what I'd do was, I'd pretend I was one of those deaf-mutes." - the Laughing Man
Morpheus011
Morpheus011
I wasn't trying to say SetDlgItemText wasn't documented, I was saying there was no documentation pertaining to any potential memory leaks concerning the use of the function.

The sending a non-null terminated string theory isn't correct because I've been using either CStrings (automatically taken care of) or string literals a la "Hello" which is implicitly null terminated.

I've been using the (EDIT: CWnd::SetDlgItemText) function, and I'm beginning to believe there may be some other issue here, especially since the larger memory leak only occurs when SetDlgItemText is commented in. I've commented out all code that even remotely relates to rendering or logic, and there is no dynamic memory being used anywhere in the program currently. Pretty much all I'm doing is handling an OnTimer event and updating all the edit controls in the dialog box.

Another strange occurance is that the Task Manager is showing jumps in my memory footprint when I do nothing but move the mouse inside the client area. I'm starting to wonder if these two issues may be related in some way, has anyone else noticed strange memory leaks in MFC Dialog based apps before?
Morpheus011
Morpheus011
ok, I'm assuming this issue is unique, but I'll give it one last bump.
iMalc
iMalc
Perhaps you are not removing certain messages from your message queue?
Are you using PeekMessage without PM_REMOVE?
yadango
yadango
what type of control are you sending the text to? are you even sending 4 KB of data to that control every second? it seems too odd to be sending that much data to a standard windows control. is it a custom control? more info on the control would be helpful (that is, if it really truly is a problem with sending text to it and not something else in your program).

anyways for stuff like this GDI leaks are the most common problem. try looking at this page and run the GdiCount program for your tool's PID. if the count keeps going up and up and up, you got a GDI leak. if i recall right there's another tool on there that tells you which objects are bitmaps, fonts, ect. and will give you a clue on what to look for in your program.

[Edited by - yadango on December 30, 2006 1:44:45 AM]
Morpheus011
Morpheus011
there's no GDI stuff going on in this project at all, and the SetDlgItemText is just sending a short string to a standard EditControl.

We're also not overriding OnIdle, only OnTimer. We do call the base class OnTimer .

I would definitely tend to agree that an issue such as this would generally be in my code and not in MFC or any other MS code. The problem is I'm not doing anything other then handling the OnTimer event and updating the EditControl with the SetDlgItemText call. Inside OnTimer I call the CDialog::OnTimer() and then call my function UpdateEditControls, which currently only calls SetDlgItemText. This is the only code running in the app and the issue persists.

I'm banking on Task Manager not being accurate, or something similar, as it would make no sense that these fairly standard MFC calls are causing leaks. I'm not handling messages like that iMalc as this is an MFC dialog based app and we're not in Win32.

Thanks for all your replies, I'm thinking a more accurate memory tracker is in order. I think a memory manager would be overkill for this tool as it's real small scale, and there's absolutely no dynamic allocation going on. The memory manager would take longer to write then the tool itself :)

Again, thank you all.
Endurion
Endurion
If you create a simple new dialogbased app and do the same, what happens? The same leak effect?

If yes, please share the text setting code.
Fruny: Ftagn! Ia! Ia! std::time_put_byname! Mglui naflftagn std::codecvt eY'ha-nthlei!,char,mbstate_t>

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.