Jump to content
  • Advertisement
Sign in to follow this  
Antonym

Memory Leak Detection(VisualStudio)

This topic is 2993 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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]

Share this post


Link to post
Share on other sites
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>

//...


Share this post


Link to post
Share on other sites
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_H

class 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


Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!