Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: memory leaks in sf::window?  (Read 4097 times)

0 Members and 1 Guest are viewing this topic.

16bit_port

  • Newbie
  • *
  • Posts: 5
    • View Profile
memory leaks in sf::window?
« on: July 14, 2011, 11:23:45 pm »
I re-compiled sfml-system and sfml-window through VS2010

simple test program
Code: [Select]

//////// Used to check memory leaks
    #include <stdlib.h>
    #include "LeakCheck.h"
    #undef THIS_FILE
    static char THIS_FILE[] = __FILE__;

#include <SFML/Window.hpp>

#pragma comment( lib, "sfml-system-d" )
#pragma comment( lib, "sfml-window-d" )

int main()
{
    #ifdef _DEBUG
        _CrtSetDbgFlag ( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF );
        _CrtDumpMemoryLeaks();
    #endif

    sf::Window App;

    return 0;
}


and here is my output :
Code: [Select]

Detected memory leaks!
Dumping objects ->
{130} normal block at 0x006C4858, 8 bytes long.
 Data: <        > BC A2 03 10 00 00 00 00
{129} normal block at 0x006C4808, 20 bytes long.
 Data: < Hl  Hl  Hl     > 08 48 6C 00 08 48 6C 00 08 48 6C 00 CD CD CD CD
{128} normal block at 0x006C47C0, 8 bytes long.
 Data: < Fl     > 0C 46 6C 00 00 00 00 00
{127} normal block at 0x006C4600, 384 bytes long.
 Data: < =           Gl > 88 3D 03 10 01 00 00 00 01 00 00 00 C0 47 6C 00
{126} normal block at 0x006C45C0, 4 bytes long.
 Data: < Fl > 00 46 6C 00
Object dump complete.
The thread 'Win32 Thread' (0x930) has exited with code 0 (0x0).
The thread 'Win32 Thread' (0x120) has exited with code 0 (0x0).
Detected memory leaks!
Dumping objects ->
{129} normal block at 0x006C4808, 20 bytes long.
 Data: < Hl  Hl  Hl     > 08 48 6C 00 08 48 6C 00 08 48 6C 00 CD CD CD CD
{128} normal block at 0x006C47C0, 8 bytes long.
 Data: < Fl     > 0C 46 6C 00 00 00 00 00
{127} normal block at 0x006C4600, 384 bytes long.
 Data: < =           Gl > 88 3D 03 10 01 00 00 00 01 00 00 00 C0 47 6C 00
{126} normal block at 0x006C45C0, 4 bytes long.
 Data: < Fl > 00 46 6C 00
Object dump complete.
The program '[3888] test SFML.exe: Native' has exited with code 0 (0x0).


LeakCheck.h
Code: [Select]

#ifdef _MSC_VER
    #include "NewDebug.h"
    #ifdef _DEBUG
        //WARNING: no matching operator delete found; memory will not be freed if initialization throws an exception
        #pragma warning( disable: 4291 )
        #define new NEW_DEBUG
    #endif
#endif


NewDebug.h
Code: [Select]

#ifndef _NEW_DEBUG_H
#define _NEW_DEBUG_H
    #include <crtdbg.h>
    #ifdef _DEBUG
        void* operator new( size_t BlockSize, const char *File, int Line );
        #define NEW_DEBUG new( THIS_FILE, __LINE__ )
        #define malloc(Size) _malloc_dbg( Size, _NORMAL_BLOCK, THIS_FILE, __LINE__  );
    #endif
#endif


NewDebug.cpp
Code: [Select]

#ifdef _MSC_VER
    #pragma warning (disable: 4514 ) // Suppress 'unreferenced inline function has been removed'
    #ifdef _DEBUG
        #include <crtdbg.h>
        void* operator new( size_t Size, const char * FileName, int Line )
        {
            return ::operator new( Size, _NORMAL_BLOCK, FileName, Line );
        }
    #endif
#endif


What's going on? I'm looking at the source for sf::Window() and it's an empty constructor, so what could be causing this so-called memory leak?

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6286
  • Thor Developer
    • View Profile
    • Bromeon
memory leaks in sf::window?
« Reply #1 on: July 14, 2011, 11:50:22 pm »
The problem has already occurred -- probably, the visual studio leak detector is not reliable or you are using it wrong. I don't know, I only trust my self-written memory control tool :P

With it, I can't reconstruct your leaks. Which SFML version are you using (if SFML 2, which revision)?
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

16bit_port

  • Newbie
  • *
  • Posts: 5
    • View Profile
memory leaks in sf::window?
« Reply #2 on: July 15, 2011, 12:22:51 am »
I'm using 1.6 and I re-compiled it through VS2010.

The leaks aren't the same as the one in that old thread (it's actually significantly larger), but according to your old post you're saying that it could just be that at the time of the reporting the memory wasn't freed yet but eventually is?

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6286
  • Thor Developer
    • View Profile
    • Bromeon
memory leaks in sf::window?
« Reply #3 on: July 15, 2011, 12:24:12 am »
Yes.

I am not sure about 1.6 however, it has been a long time since I used it. You could try with SFML 2, it contains many improvements and bugfixes anyway.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

JAssange

  • Full Member
  • ***
  • Posts: 104
    • View Profile
memory leaks in sf::window?
« Reply #4 on: July 15, 2011, 03:31:00 am »
You're dumping memory leaks before the end of the program, so of course there will still be allocated memory. Not to mention that function is just broken in general. Use a proper detector like Valgrind or Rational Purify if you're really worried about it.