Results 1 to 10 of 10

Thread: Memory leak problems in C++

  1. #1
    Join Date
    Jan 2010
    Posts
    79

    Memory leak problems in C++

    I'm a beginner in C++ programming language. (So I am not having enough knowledge about it) After studying some basic concepts of C++, I found that there is some memory leaks problem in it. I just want to know more about it, since we have been given very less notes of memory leak. So expecting some useful information from you guys about the memory leak problems in C++.

  2. #2
    Join Date
    Mar 2008
    Posts
    672

    Re: Memory leak problems in C++

    The ability to allocate and deallocate memory dynamically is one of the strongest features of C / C + +, but the greatest asset can also become the main weakness. This is certainly true in some applications C / C + +, where problems of memory management bugs are among the most common. Fortunately, the Visual Studio and the C runtime libraries (CRT) provides effective means to detect and identify memory leaks.

  3. #3
    Join Date
    Feb 2008
    Posts
    102

    Re: Memory leak problems in C++

    One of the more subtle bugs and more difficult to detect is the memory leak, failure to properly deallocate memory that was previously allocated. A small memory leak that occurs only once can go unnoticed, but programs that lose large amounts of memory or leaking slowly may have symptoms ranging from performance degradation (with a gradual decrease in the latter) lack of memory pure and simple. Worse, a program that leaks can monopolize so much memory that may cause the failure of another program, the user will then have no track to locate the problem. Furthermore, memory leaks, even harmless, may be symptomatic of other problems.

  4. #4
    Join Date
    Oct 2008
    Posts
    132

    Re: Memory leak problems in C++

    The main tools for detecting memory leaks are the debugger and the debug heap functions of C runtime libraries (CRT). To enable the Debug Heap, include the following statements in your program :
    Code:
     # Define _CRTDBG_MAP_ALLOC
     Stdlib.h
     # Include <crtdbg.h>
    You should know that an Include statements must appear in the order shown here. If you change this order, the functions you are using may not work.

  5. #5
    Join Date
    Oct 2008
    Posts
    127

    Re: Memory leak problems in C++

    With the inclusion of crtdbg.h, you map the functions malloc and free in their versions Debug _malloc_dbg and _free_dbg, who monitor the allocation and deallocation of memory. This mapping only occurs in Debug version (when _DEBUG is defined). Release versions use ordinary functions malloc and free. The # define statement maps the base versions of the CRT heap functions corresponding debug versions. You do not absolutely need this training, but in his absence, the dump memory leaks less information useful.

  6. #6
    Join Date
    Feb 2006
    Posts
    185

    Re: Memory leak problems in C++

    After adding the instructions mentioned above, you can dump the memory leaks of information including the following statement in your program :
    Code:
     _CrtDumpMemoryLeaks ();
    When you run your program beneath the debugger, _CrtDumpMemoryLeaks print information about memory leaks in the Output window. This information looks reminiscent of this :
    Code:
     Detected memory leaks!
     Dumping objects ->
     C: \ PROGRAM FILES \ VISUAL STUDIO \ MyProjects \ Leaktest \ leaktest.cpp (20): (18) 
     normal block at 0x00780E80, 64 bytes long.
      Data: <> CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD
     Object dump complete.

  7. #7
    Join Date
    Oct 2005
    Posts
    2,393

    Re: Memory leak problems in C++

    If _CRTDBG_MAP_ALLOC is not set, the display shows :
    • number of memory allocation (between brackets);
    • the block type (normal, client, or CRT);
    • the memory location in hexadecimal format;
    • data size in bytes;
    • content of the first 16 bytes (also in hexadecimal).

    _CRTDBG_MAP_ALLOC When set, the display also shows the file in which the lost memory was allocated. The number in brackets listed after the file name (20 in this example) indicates the line number within the file.

  8. #8
    proximityinfotech6 Guest

    Re: Memory leak problems in C++

    Found a new Video that is showing the original OASE Jumping jet close up.
    Ohh no! Cant beleve Poor quality, bad cut bad stream at the end .... i am disappointed. What you think about this one.

  9. #9
    Join Date
    May 2008
    Posts
    2,389

    Re: Memory leak problems in C++

    Calling _CrtDumpMemoryLeaks is fairly simple if your program always stops at the same location. If your program can stop at several locations, instead of placing a call to _CrtDumpMemoryLeaks at each location where the program may stop, you can include the following call to start the program :
    Code:
    _CrtSetDbgFlag (_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
    This statement calls _CrtDumpMemoryLeaks automatically when your program stops. You must set both bit fields, and _CRTDBG_ALLOC_MEM_DF _CRTDBG_LEAK_CHECK_DF as indicated above.

  10. #10
    Join Date
    Nov 2008
    Posts
    1,192

    Re: Memory leak problems in C++

    By default, _CrtDumpMemoryLeaks is a dump of information from memory leaks in the Debugging pane of the Output window, as described above. Feel free to modify this configuration to make a dump of information to another location with _CrtSetReportMode. If you use a library, it can redefine the output to another location. In this case, you can redefine the location of the output in the Output window using the following statement:
    Code:
    _CrtSetReportMode (_CRT_ERROR, _CRTDBG_MODE_DEBUG);

Similar Threads

  1. svchost.exe consumes CPU and Memory - Memory Leak?
    By Chad Gross in forum Windows XP Support
    Replies: 1
    Last Post: 25-03-2013, 12:46 PM
  2. Memory leak in Firefox 3.6.11
    By Eric Banadinovich in forum Technology & Internet
    Replies: 4
    Last Post: 19-04-2011, 07:57 PM
  3. Memory Leak 60 to 30-40 fps in Crysis 2
    By Krisoijn in forum Motherboard Processor & RAM
    Replies: 5
    Last Post: 25-03-2011, 10:16 PM
  4. How to compare states of memory in memory leak?
    By Bottlenecked in forum Windows Software
    Replies: 4
    Last Post: 24-06-2010, 06:35 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,711,663,169.69221 seconds with 17 queries