[c++] Memory leaks

Started by
3 comments, last by SiCrane 14 years, 1 month ago
Hi! I wrote a little game application just for try a graphic engine, and when I looked for memory leaks with _CrtDumpMemoryLeaks() the result was:

Detected memory leaks!
Dumping objects ->
{139} normal block at 0x004E4D00, 1 bytes long.
 Data: < > 00 
{138} normal block at 0x004E4CC0, 1 bytes long.
 Data: < > 00 
{137} normal block at 0x004E4C80, 1 bytes long.
 Data: < > 00 
{136} normal block at 0x004E4C40, 1 bytes long.
 Data: < > 00 
Object dump complete.
I checked again my code and all seemed be ok. So, I tried with a empty main() and the result was the same.. Why?
Advertisement
You can try to use debug function to break to the given allocation:
#include <crtdbg.h>// Put in first line of main()._CrtSetBreakAlloc(136);

If the allocation happens before main(), ie from global objects, you can try to to set the breakpoint in the Watch window
Quote:Original post by Michelepa87
I tried with a empty main() and the result was the same.. Why?
Do you have globals that allocate memory?

C++: A Dialog | C++0x Features: Part1 (lambdas, auto, static_assert) , Part 2 (rvalue references) , Part 3 (decltype) | Write Games | Fix Your Timestep!

Now my code is:

#define _CRTDBG_MAP_ALLOC#include <crtdbg.h>int main(){    _CrtSetDbgFlag( _CRTDBG_LEAK_CHECK_DF | _CRTDBG_ALLOC_MEM_DF );    _CrtDumpMemoryLeaks();    return 0;}


and I still have leaks problems.
I tried to set breakpoints on a memory allocation number but nothing happened.
If you use _CrtSetDbgFlag() to schedule a leak test you don't also call _CrtDumpMemoryLeaks() to check for leaks manually.

This topic is closed to new replies.

Advertisement