Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I had a similar problem using SDL library as well. In my case though, I was trying to use the default Memory Leak detection of Visual Studio 2010 because I didn't wanted to use a third party library/application.</p> <h1>Fixing the issue</h1> <p>If after all the required includes, define and function call you still don't see any memory leaks printed out, it might be that your Runtime Library is not set properly. </p> <p>Double check if you have the debug version of the Runtime Library instead of the non-debug one (/MT and /MD).</p> <p><strong>Multi-threaded Debug (/MTd)</strong></p> <p><strong>Multi-threaded Debug DLL (/MDd)</strong></p> <blockquote> <p>The compiler defines _DEBUG when you specify the /MTd or /Mdd option. These options specify debug versions of the C run-time library. <a href="http://msdn.microsoft.com/en-us/library/0b98s6w8%28v=vs.71%29.aspx" rel="nofollow">See _DEBUG reference MSDN</a></p> </blockquote> <p>Thus, the _DEBUG symbol must be defined in order to enable CRT code.</p> <blockquote> <p>[...] When _DEBUG is not defined, calls to _CrtSetDbgFlag are removed during preprocessing [...]. <a href="http://msdn.microsoft.com/en-us/library/5at7yxcs%28v=vs.71%29.aspx" rel="nofollow">See MSDN reference</a></p> </blockquote> <p>So building a debug build is not enough to ensure _DEBUG will be defined.</p> <p><em>This is something that you usually don't change in a normal project, but following a tutorial for SDL could lead you were I was.</em></p> <p>Hopefully, it is going to help someone else, or even you.</p> <h2>More Details below</h2> <p>I was following the <a href="http://msdn.microsoft.com/en-us/library/e5ewb1h3%28v=vs.80%29.aspx" rel="nofollow">MSDN page</a> to enable Memory leak detection out of the box with VS 2010.</p> <p>After declaring those</p> <pre><code>#define _CRTDBG_MAP_ALLOC #include &lt;stdlib.h&gt; #include &lt;crtdbg.h&gt; </code></pre> <p>I enabled them into my code and I inserted a deliberate memory leak</p> <pre><code>int main( int argc, char* args[] ) { _CrtSetDbgFlag( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF ); _CrtSetReportMode( _CRT_ERROR, _CRTDBG_MODE_DEBUG ); int *pArray = (int*)malloc(sizeof(int) * 24); // Memory not freed return 0; } </code></pre> <p>Nothing was printed out. </p> <p>So, I looked at the assembly and it was definitively not generating the CRT code at all as you can see:</p> <pre><code>int main( int argc, char* args[] ) { 012932F0 push ebp 012932F1 mov ebp,esp 012932F3 sub esp,0CCh 012932F9 push ebx 012932FA push esi 012932FB push edi 012932FC lea edi,[ebp-0CCh] 01293302 mov ecx,33h 01293307 mov eax,0CCCCCCCCh 0129330C rep stos dword ptr es:[edi] _CrtSetDbgFlag( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF ); _CrtSetReportMode( _CRT_ERROR, _CRTDBG_MODE_DEBUG ); // Nothing in both case! int *pArray = (int*)malloc(sizeof(int) * 24); 0129330E mov esi,esp 01293310 push 60h 01293312 call dword ptr [__imp__malloc (129E4CCh)] 01293318 add esp,4 0129331B cmp esi,esp 0129331D call @ILT+580(__RTC_CheckEsp) (1291249h) 01293322 mov dword ptr [pArray],eax </code></pre> <p>Then, I realized that the _DEBUG symbol was probably not getting defined.</p>
 

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