Weird memory leak reports

Started by
4 comments, last by Stragen 10 years, 5 months ago

Hello, I read this http://msdn.microsoft.com/en-us/library/e5ewb1h3(v=vs.71).aspx (tells you how to detect memory leaks in VS) and I applied it to my project but I got some unexpected results. I am not even dynamically allocating anything and it tells me I have a bunch of memory leaks.


Detected memory leaks!
Dumping objects ->
{173} normal block at 0x038F9D90, 20 bytes long.
 Data: <8.s 8.s 8.s     > 38 2E 73 00 38 2E 73 00 38 2E 73 00 01 00 CD CD 
{172} normal block at 0x038F3408, 24 bytes long.
 Data: <@4              > 40 34 8F 03 FF FF FF FF 00 00 00 00 00 00 00 00 
{171} normal block at 0x0360EEA0, 40 bytes long.
 Data: <   _            > D4 C5 C3 5F 18 00 00 00 08 00 00 00 00 00 00 00 
{170} normal block at 0x0072BCF0, 40 bytes long.
 Data: <   _            > D4 C5 C3 5F 18 00 00 00 08 00 00 00 00 00 00 00 
{151} normal block at 0x007335B0, 32 bytes long.
 Data: <Platformer Studi> 50 6C 61 74 66 6F 72 6D 65 72 20 53 74 75 64 69 
{150} normal block at 0x00727620, 8 bytes long.
 Data: < %      > 9C 25 08 01 00 00 00 00 
{147} normal block at 0x00732F60, 24 bytes long.
 Data: < /s             > 98 2F 73 00 FF FF FF FF 00 00 00 00 00 00 00 00 
{146} normal block at 0x00732ED0, 24 bytes long.
 Data: < /s             > 08 2F 73 00 FF FF FF FF 00 00 00 00 00 00 00 00 
{145} normal block at 0x00732E88, 8 bytes long.
 Data: <8# _    > 38 23 C4 5F 00 00 00 00 
{144} normal block at 0x00732E38, 20 bytes long.
 Data: <                > 90 9D 8F 03 90 9D 8F 03 90 9D 8F 03 01 01 CD CD 
{143} normal block at 0x00732DF8, 4 bytes long.
 Data: <    > 0C 00 00 00 
{142} normal block at 0x00732DB8, 4 bytes long.
 Data: <    > 0B 00 00 00 
Object dump complete.

My Code:


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

#include <SFML/Graphics.hpp>
#include <string>
#include <sstream>
#include <iostream>

//window attributes
const unsigned int WINDOW_WIDTH = 800;
const unsigned int WINDOW_HEIGHT = 600;
const unsigned int MAX_FPS = 60;
const std::string WINDOW_NAME = "Platformer Studio v 1.0 inDev";

int main(){
	sf::RenderWindow window(sf::VideoMode(WINDOW_WIDTH, WINDOW_HEIGHT), WINDOW_NAME, sf::Style::Close);

	sf::Event event;
	sf::Clock fpsTimer, updTimer;
	int frames = 0;

	window.setFramerateLimit(MAX_FPS);

	while(window.isOpen()){
		//events
		while(window.pollEvent(event)){
			switch(event.type){
			case sf::Event::Closed:
				window.close();
				break;
			}
		}

		//keyboard input
		if(sf::Keyboard::isKeyPressed(sf::Keyboard::Escape)) 
			window.close();

                ++frames;
		//set to a dark purple colour
		window.clear(sf::Color(80, 0, 80, 255));
		window.display();

		//get frame rate and display it in the title bar
		if(fpsTimer.getElapsedTime() >= sf::seconds(1)){
			std::stringstream sstr;
			sstr << WINDOW_NAME << "     " << frames << " fps";
			window.setTitle(sstr.str());

			frames = 0;
			fpsTimer.restart();
		}
	}

	_CrtDumpMemoryLeaks();
	return 0;
} 

What does this mean? I am using VS2012 and SFML 2.0. thanks for any help

Advertisement

Hello, you should use "#define _CRTDBG_MAP_ALLOC" instead of #define CRTDBG_MAP_ALLOC for more information about memory leaks.

Btw i have no idea, maybe it don't just watch the heap, so when you call it you use memory on stack for your window, an event, 2 clock and an int.

Try to put your whole code in a {} block except that:

" _CrtDumpMemoryLeaks();
return 0;"

It's just a tip, but i think it's worth a try.

Check this article. It has a better explanation on how to identify memory leaks.

I agree with Melkon - it's probably your local objects. They are destroyed and deallocated only after you exit main().

Remove the call to _CrtDumpMemoryLeaks(), and instead call


_CrtSetDbgFlag ( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF );

at the beginning of main. This will call _CrtDumpMemoryLeaks() automatically after you return from main(), so it shouldn't report you local objects.

I use VLD (visual leak detector) in ms vs, works pretty nice and shows you the line of code where you create something ("new") which is not deleted/freed later.

Crealysm game & engine development: http://www.crealysm.com

Looking for a passionate, disciplined and structured producer? PM me

Is it possible that you're seeing "leaks" from objects of static storage duration that are destroyed after your call to _CrtDumpMemoryLeaks()? For example, you definitely have a std::string, and it's likely there are std::cout and friends, and consider std::allocator. Also, possibly, the SFML library you're using may allocate some objects either of static storage duration or possibly allocation pools.

Stephen M. Webb
Professional Free Software Developer

Its also possible that for some reason your stringstreams.str() is not releasing memory after its copied the string contents.

I thought MS fixed that, but i've seen some strange things come up with the new VS compiler versions.

This topic is closed to new replies.

Advertisement