Memory Leak Detection(VisualStudio)

Started by
1 comment, last by Antonym 14 years ago
I am trying to setup memory leak detection with visual studio following the instruction in msdn. http://msdn.microsoft.com/en-us/library/e5ewb1h3%28VS.80%29.aspx I can get it to show the memory leaks but not the line and file.


#include "application.h"
#include "play_state.h"
#include "edit_state.h"
#include "lua.hpp"
#include "stdio.h"
#include <iostream>

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


#ifdef _DEBUG

#define DEBUG_NEW new(_NORMAL_BLOCK, __FILE__, __LINE__)

#define new DEBUG_NEW

#endif

int WINAPI WinMain(HINSTANCE hInstance,
                   HINSTANCE hPrevInstance,
                   LPSTR lpCmdLine,
                   int nCmdShow)
{

	_CrtSetDbgFlag ( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF );

	application app(SCREEN_WIDTH,SCREEN_HEIGHT);
	
	if(!app.init(hInstance,nCmdShow))
		return 0;

	app.changeState( edit_state::instance() );

	while( app.running() )
	{
		app.handleEvents();
		app.update();
		app.draw();
		app.handleMessages();
	}

	app.cleanUp();

	return 0;
}



Any help is much appreciated. Edit: I think it's also worth mentioning that in a smaller project it works without problems :S. [Edited by - Antonym on April 14, 2010 3:18:52 AM]
Advertisement
Is crtdbg.h included in any of your other headers? If so the then
#define _CRTDBG_MAP_ALLOC
is not actually controlling the compilation of crtdbg.h - you could try moving them above your other includes to be sure:

#define _CRTDBG_MAP_ALLOC#include <stdlib.h>#include <crtdbg.h>#include "application.h"#include "play_state.h"#include "edit_state.h"#include "lua.hpp"#include "stdio.h"#include <iostream>//...
I tried what you suggested though nothing changed.

I am pretty sure I haven't included crtdbg.h in any other header or file.

Another header I think may be relevant.
#ifndef GLOBALS_H#define GLOBALS_Hclass game_state;#include <windows.h>#include <windowsx.h>//D3D#if defined(DEBUG)|defined(_DEBUG)#ifndef D3D_DEBUG_INFO#define D3D_DEBUG_INFO#endif#endif//D3D?#include <d3d9.h>#include <d3dx9.h>#include <iostream>#include <vector>#include <map>#include <string>#include <algorithm>#include <fstream>#include <sstream>#include <cassert>#include "lua.hpp"#include <SFML/Audio.hpp>#pragma comment( lib, "winmm.lib" )#ifdef _DEBUG# pragma comment(lib, "d3dx9d.lib")#else# pragma comment(lib, "d3dx9.lib")#endif# pragma comment(lib, "d3d9.lib")//Bunch of typedefs#endif

This topic is closed to new replies.

Advertisement