Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can use some techniques in your code to detect memory leak. The most common and most easy way to detect is, define a macro say, DEBUG_NEW and use it, along with predefined macros like <code>__FILE__</code> and <code>__LINE__</code> to locate the memory leak in your code. These predefined macros tell you the file and line number of memory leaks.</p> <p>DEBUG_NEW is just a MACRO which is usually defined as:</p> <pre><code>#define DEBUG_NEW new(__FILE__, __LINE__) #define new DEBUG_NEW </code></pre> <p>So that wherever you use <code>new</code>, it also can keep track of the file and line number which could be used to locate memory leak in your program.</p> <p>And <code>__FILE__</code>, <code>__LINE__</code> are <a href="http://msdn.microsoft.com/en-us/library/b0084kay%28v=vs.80%29.aspx">predefined macros</a> which evaluate to the filename and line number respectively where you use them!</p> <p>Read the following article which explains the technique of using DEBUG_NEW with other interesting macros, very beautifully:</p> <p><a href="http://wyw.dcweb.cn/leakage.htm">A Cross-Platform Memory Leak Detector</a></p> <hr> <p>From <a href="http://en.wikipedia.org/wiki/Debug_new">Wikpedia</a>,</p> <blockquote> <p>Debug_new refers to a technique in C++ to overload and/or redefine operator new and operator delete in order to intercept the memory allocation and deallocation calls, and thus debug a program for memory usage. <strong>It often involves defining a macro named DEBUG_NEW, and makes new become something like new(_<em>FILE</em>_, _<em>LINE</em>_) to record the file/line information on allocation.</strong> Microsoft Visual C++ uses this technique in its Microsoft Foundation Classes. There are some ways to extend this method to avoid using macro redefinition while still able to display the file/line information on some platforms. There are many inherent limitations to this method. It applies only to C++, and cannot catch memory leaks by C functions like malloc. However, it can be very simple to use and also very fast, when compared to some more complete memory debugger solutions.</p> </blockquote>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload