SinisterMJ
SinisterMJ

Reputation: 3509

_CrtDumpMemoryLeaks not being called

I have a code in which I wanted to test how many memory allocations do happen in total, and since the crt output displays which nth memory allocation leaked, I build some leaks on purpose into my code, like

#define _CRTDBG_MAP_ALLOC  
#include <stdlib.h>  
#include <crtdbg.h>

#include <stdint.h>
#include <memory>
#include <Windows.h>
#include <time.h>

#include "ipp.h"

int main(...) {
    _CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
    _CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_DEBUG);

    double* temp0 = new double[4];
    /* do something */
    double* temp1 = new double[4];
    _CrtDumpMemoryLeaks();
    return 0;
}

but for some reason, I get no output from the DumpMemoryLeaks(). Does anyone have an idea of what could be happening here? Running in debug mode.

Edit: I also checked the disassembly, it just jumps over those _Crt lines without doing anything.

Upvotes: 0

Views: 1325

Answers (2)

Vlad Weird
Vlad Weird

Reputation: 141

Try run yours program in Debug mode: F5

Upvotes: 0

mpiatek
mpiatek

Reputation: 1343

The code you posted writes correct output to the output window in Visual Studio 2013:

Detected memory leaks! Dumping objects -> {123} normal block at 0x01140050, 32 bytes long. Data: < > CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD {122} normal block at 0x0113FFF0, 32 bytes long. Data: < > CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD Object dump complete.

Upvotes: 1

Related Questions