Sign in to follow this  

Leaking memory in VS2005/C++ debug mode.

This topic is 3742 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm having this weird issue, in debug mode of VS2005 (c++) I'm leaking basically ALL allocated memory, including std:: objects that pushed something. No. My destructors are fine, every new has a delete, yes, I've checked it. Yes, a few times. The main point of interest is that the memory leaks in debug (f5) mode, and not in compile+run (ctrl+f5) mode. To clarify it even more, it leaks the memory exclusively only when closing the app. Yes destructors are (should be) called, and complete. I've spent quite a few hours tonight, learned how to use CRT heap debug commands and all of that. After some more fiddling I've noticed when it 'leaks' the memory and when not. I think that whole heap is dumped as memory leak into output window for no reason. Is this normal? Or should I be worried about anything? This happens only when closing my app, so it doesn't really impact anything. I'm just curious about the cause of this. Thanks for any insight you might have.

Share this post


Link to post
Share on other sites
I had the same issue.I guess its not a leak actually.
Where are you calling the CrtDump functions?
Those reported memory may be freed after the end of your main function where global and static objects are freed.

For example each std::string which holds something long is reported as a memory leak if i call the memory function just before my main ends.
I guess the string class holds some internall static buffer for optimization which is freed when the application ends.

Share this post


Link to post
Share on other sites
I was calling them straight after 'new' allocations.

Found that both nodes of my tree, and std::map, std::string, std::vector objects were included in that list (2500 entries, raging from 16 to 200+ bytes).

This occured only in DEBUG mode, and does not occur at all in run-time. My assumption is that the debugger does not initiate the destructors of all classes, thus reporting the data as memory leak.

Maybe its a hidden feature left by redmond engineers, but with applications that produce hundreds of megabytes during run-time, this might mean a 5 minute break after each closure of application. Which is not very welcome.

Share this post


Link to post
Share on other sites
I noticed the same thing a while ago, and after a bit of hunting around I discovered that it is a known bug in the VS version of stl that only occurs in debug mode. There is a fix in windows update apparently, and there are several manual fixes around. I had a quick look to find some other threads as reference but couldn't find them. A quick search should bring up a few.

Share this post


Link to post
Share on other sites

This topic is 3742 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this