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

Author Topic: [SFML2] sf::Window create close memory issue  (Read 11073 times)

0 Members and 1 Guest are viewing this topic.

solgar

  • Newbie
  • *
  • Posts: 36
    • View Profile
[SFML2] sf::Window create close memory issue
« on: November 21, 2009, 03:41:50 pm »
Running following code constantly consumes RAM. Running for 1 minute consumes ~10 mb of memory.

Code: [Select]
#include <SFML/Window.hpp>

using namespace std;

int main()
{
    sf::Window* wnd = new sf::Window(sf::VideoMode(800, 600, 32), "SFML_test", sf::Style::Close|sf::Style::Titlebar|sf::Style::Resize, sf::ContextSettings(32, 8, 0));
    while( wnd->IsOpened() )
    {
        wnd->Display();
        wnd->Close();
        wnd->Create(sf::VideoMode(800, 600, 32), "SFML_test", sf::Style::Close|sf::Style::Titlebar|sf::Style::Resize, sf::ContextSettings(32,8,0));
    }
return 0;
}


Why is that? Code seems to be valid usage of Close() and Create() methods. I am using Xubuntu linux.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
[SFML2] sf::Window create close memory issue
« Reply #1 on: November 21, 2009, 10:43:17 pm »
Hi

I've tested your code and indeed I found a memory leak... on Windows :D

I'll do the same test on Linux.

Thanks for your feedback :)
Laurent Gomila - SFML developer

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
[SFML2] sf::Window create close memory issue
« Reply #2 on: November 22, 2009, 11:16:45 am »
I fixed a leak in the Linux implementation, however valgrind still outputs leaks from XCreatePixmap and XOpenIM, although I properly call the corresponding Free functions. I'm not sure whether or not this is SFML's fault.
Laurent Gomila - SFML developer

Zerd

  • Newbie
  • *
  • Posts: 9
    • View Profile
[SFML2] sf::Window create close memory issue
« Reply #3 on: December 16, 2009, 09:05:28 pm »
Hi!

Did you manage do find the leak on windows?
I started using sfml and almost directly ran into this leak by using this code:
Code: [Select]
#ifdef _DEBUG
#define _CRTDBG_MAP_ALLOC
#include <stdlib.h>
#include <crtdbg.h>
#endif

#include <SFML/graphics.hpp>


INT WINAPI WinMain(HINSTANCE Instance, HINSTANCE, LPSTR, INT) {

sf::RenderWindow renderWindow(sf::VideoMode(800, 600, 32), "SFML Graphics");


while(renderWindow.IsOpened()) {
        // Process events
        sf::Event Event;
        while (renderWindow.GetEvent(Event))
        {
            // Close window : exit
            if (Event.Type == sf::Event::Closed)
                renderWindow.Close();
}

// Fill the background black
renderWindow.Clear(sf::Color(0, 0, 0, 255));

        // Display window contents on screen
        renderWindow.Display();
}

#ifdef _DEBUG
_CrtDumpMemoryLeaks();
#endif

return EXIT_SUCCESS;
}


Is there a way to fix this issue?
Thank you
- Zerd

*edit*
Sorry its not really related to this topic, I'm using SFML-1.5 for VS2008

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
[SFML2] sf::Window create close memory issue
« Reply #4 on: December 16, 2009, 09:14:42 pm »
Quote
Did you manage do find the leak on windows?

The one I was talking about previously had been resolved immediately.

Which reversion of SFML2 do you use? Can you show the output of _CrtDumpMemoryLeaks()?
Laurent Gomila - SFML developer

Zerd

  • Newbie
  • *
  • Posts: 9
    • View Profile
[SFML2] sf::Window create close memory issue
« Reply #5 on: December 16, 2009, 09:20:22 pm »
Sorry, I'm not using version 2 I'm using 1.5 for Visual Studio 2008 (on a x64 pc)
I suppose I also am in the wrong forum... :( I'm sorry for that...

Quote
Detected memory leaks!
Dumping objects ->
{152} normal block at 0x01EE79F8, 16 bytes long.
 Data: <        }       > 0A 00 00 00 82 00 00 00 7D 01 00 00 CC CC CC CC
{151} normal block at 0x01EE79A8, 16 bytes long.
 Data: <                > 02 00 00 00 CC CC CC CC CC CC CC CC CC CC CC CC
{150} normal block at 0x01EE7948, 32 bytes long.
 Data: < y   y          > A8 79 EE 01 F8 79 EE 01 00 00 00 00 00 00 00 00
{135} normal block at 0x01EE7000, 20 bytes long.
 Data: < p   p   p      > 00 70 EE 01 00 70 EE 01 00 70 EE 01 CD CD CD CD
{134} normal block at 0x01EE3D88, 216 bytes long.
 Data: <| Q             > 7C 15 51 00 01 00 00 00 01 00 00 00 00 00 00 00
{133} normal block at 0x01EE3D48, 4 bytes long.
 Data: < =  > 88 3D EE 01
Object dump complete.


Thats my problem, it doesn't really say where the memory is leaking...

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
[SFML2] sf::Window create close memory issue
« Reply #6 on: December 16, 2009, 09:22:24 pm »
So it's probably the one I fixed above... ;)
Laurent Gomila - SFML developer

Zerd

  • Newbie
  • *
  • Posts: 9
    • View Profile
[SFML2] sf::Window create close memory issue
« Reply #7 on: December 16, 2009, 10:14:52 pm »
I just downloaded and built the latest trunk and it's still leaking. So I guess its not the same problem ;)

Quote
Detected memory leaks!
Dumping objects ->
{152} normal block at 0x01ED7A00, 16 bytes long.
 Data: <                > 0A 00 00 00 0D 00 00 00 06 01 00 00 CC CC CC CC
{151} normal block at 0x01ED79B0, 16 bytes long.
 Data: <                > 02 00 00 00 CC CC CC CC CC CC CC CC CC CC CC CC
{150} normal block at 0x01ED7950, 32 bytes long.
 Data: < y   z          > B0 79 ED 01 00 7A ED 01 00 00 00 00 00 00 00 00
{135} normal block at 0x01ED7000, 20 bytes long.
 Data: < p   p   p      > 00 70 ED 01 00 70 ED 01 00 70 ED 01 CD CD CD CD
{134} normal block at 0x01ED3D88, 224 bytes long.
 Data: < DQ             > 0C 44 51 00 01 00 00 00 01 00 00 00 00 00 00 00
{133} normal block at 0x01ED3D48, 4 bytes long.
 Data: < =  > 88 3D ED 01
Object dump complete.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
[SFML2] sf::Window create close memory issue
« Reply #8 on: December 16, 2009, 10:44:28 pm »
I'm not sure that I fixed it in the trunk :lol:
Laurent Gomila - SFML developer

Zerd

  • Newbie
  • *
  • Posts: 9
    • View Profile
[SFML2] sf::Window create close memory issue
« Reply #9 on: December 16, 2009, 10:52:43 pm »
Doh... OK, I'll try again tomorrow... :)

Zerd

  • Newbie
  • *
  • Posts: 9
    • View Profile
[SFML2] sf::Window create close memory issue
« Reply #10 on: December 17, 2009, 10:03:34 pm »
I'm sorry to say that, but with the latest svn version it's still leaking  :oops:

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
[SFML2] sf::Window create close memory issue
« Reply #11 on: December 17, 2009, 10:38:17 pm »
Latest revision in branches/sfml2?
Laurent Gomila - SFML developer

Zerd

  • Newbie
  • *
  • Posts: 9
    • View Profile
[SFML2] sf::Window create close memory issue
« Reply #12 on: December 18, 2009, 09:59:40 am »
Yes, branches/sfml2

With the same source I posted earlier...

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
[SFML2] sf::Window create close memory issue
« Reply #13 on: December 18, 2009, 10:42:27 am »
What if you remove the calls to Clear and Display?
Laurent Gomila - SFML developer

Zerd

  • Newbie
  • *
  • Posts: 9
    • View Profile
[SFML2] sf::Window create close memory issue
« Reply #14 on: December 18, 2009, 12:00:23 pm »
Alone this code creates a leak:

Code: [Select]
#ifdef _DEBUG
   #define _CRTDBG_MAP_ALLOC
   #include <stdlib.h>
   #include <crtdbg.h>
#endif

#include <SFML/graphics.hpp>


int main() {

   sf::RenderWindow renderWindow(sf::VideoMode(800, 600, 32), "SFML Graphics");

#ifdef _DEBUG
   _CrtDumpMemoryLeaks();
#endif

   return EXIT_SUCCESS;
}