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

Author Topic: Memory Leaks.. no idea where its coming from!  (Read 4703 times)

0 Members and 1 Guest are viewing this topic.

Roose Bolton of the Dreadfort

  • Full Member
  • ***
  • Posts: 113
  • Full-time Procrastinator, Part-time programmer.
    • View Profile
    • Personal Portfolio/Website/Blog
Memory Leaks.. no idea where its coming from!
« on: May 30, 2012, 09:21:08 pm »
I have been fighting memory leaks that I cannot find for about 2 hours - I have started a new project and I am using the built in function

Code: [Select]
_CrtDumpMemoryLeaks();

and its picking up numerous memory leaks - is this an SFML bug or a problem with SFML and the function?

Whats going on?
« Last Edit: May 30, 2012, 09:29:28 pm by 1337matty »
Trying so very hard to finish at-least one project.

Watch out for the RAII police, they will get you.

www.bantersaurus-games.com

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Memory Leaks.. no idea where its coming from!
« Reply #1 on: May 30, 2012, 09:54:53 pm »
Which memory leaks? If you don't provide detailed information we won't be able to help you.

And don't forget that SFML has global objects that might be destroyed after your memory leak report is generated. Are all the "leaks" detected at application exit?
Laurent Gomila - SFML developer

Acrobat

  • Full Member
  • ***
  • Posts: 153
    • View Profile
Re: Memory Leaks.. no idea where its coming from!
« Reply #2 on: May 30, 2012, 10:41:21 pm »
are you using singletons ?

Roose Bolton of the Dreadfort

  • Full Member
  • ***
  • Posts: 113
  • Full-time Procrastinator, Part-time programmer.
    • View Profile
    • Personal Portfolio/Website/Blog
Re: Memory Leaks.. no idea where its coming from!
« Reply #3 on: May 31, 2012, 01:06:22 am »
Sorry,

The code I am running the test

Code: [Select]
#include <SFML/Audio.hpp>
 #include <SFML/Graphics.hpp>
 
 int main()
 {
     // Create the main window
     sf::RenderWindow window(sf::VideoMode(800, 600), "SFML window");

     // Start the game loop
     while (window.isOpen())
     {
         // Process events
         sf::Event event;
         while (window.pollEvent(event))
         {
             // Close window : exit
             if (event.type == sf::Event::Closed)
                 window.close();
         }
 
         // Clear screen
         window.clear();
 
         // Update the window
         window.display();
     }
 
     _CrtDumpMemoryLeaks();
     return EXIT_SUCCESS;
 }


and the mem leak reports;

Code: [Select]

Detected memory leaks!
Dumping objects ->
{159} normal block at 0x001A52E0, 4 bytes long.
 Data: <4"0 > 34 22 30 00
{150} normal block at 0x001A5290, 20 bytes long.
 Data: < L   L   L   Q  > 98 4C 1A 00 98 4C 1A 00 98 4C 1A 00 D0 51 1A 00
{149} normal block at 0x001A5238, 24 bytes long.
 Data: <                > E0 17 86 00 FF FF FF FF 00 00 00 00 00 00 00 00
{148} normal block at 0x001A51D0, 40 bytes long.
 Data: < A R            > A4 41 AF 52 18 00 00 00 08 00 00 00 00 00 00 00
{146} normal block at 0x001A4F18, 40 bytes long.
 Data: < A R            > A4 41 AF 52 18 00 00 00 08 00 00 00 00 00 00 00
{145} normal block at 0x001A4ED0, 8 bytes long.
 Data: <t M     > 74 F6 4D 00 00 00 00 00
{142} normal block at 0x001A4D40, 24 bytes long.
 Data: <H               > 48 F8 84 00 FF FF FF FF 00 00 00 00 00 00 00 00
{141} normal block at 0x001A4CE8, 24 bytes long.
 Data: <                > 10 F8 84 00 FF FF FF FF 00 00 00 00 00 00 00 00
{140} normal block at 0x001A4C98, 20 bytes long.
 Data: < R   R   R      > 90 52 1A 00 90 52 1A 00 90 52 1A 00 CD CD CD CD
{139} normal block at 0x001A4C50, 8 bytes long.
 Data: <   R    > BC 92 AF 52 00 00 00 00
{138} normal block at 0x001A4C10, 4 bytes long.
 Data: <    > 0D 00 00 00
{137} normal block at 0x001A4BD0, 4 bytes long.
 Data: <    > 0C 00 00 00
Object dump complete.


as you can see I am doing

Code: [Select]
_CrtDumpMemoryLeaks();

before

Code: [Select]
return EXIT_SUCCESS;

Would that pick up these problems your talking about?
« Last Edit: May 31, 2012, 01:08:21 am by 1337matty »
Trying so very hard to finish at-least one project.

Watch out for the RAII police, they will get you.

www.bantersaurus-games.com

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11032
    • View Profile
    • development blog
    • Email
Re: Memory Leaks.. no idea where its coming from!
« Reply #4 on: May 31, 2012, 01:35:43 am »
You're search for memory leaks and hunting ghosts but you don't understand the working of scope lifetime?

I'm not an expert on anything but afaik you create a render window in the scope of your main function. Since you're not destroying it anywhere, it will get destroyed once the main scope is left, thus in return EXIT_SUCCESS;. But you're checking for memory leaks BEFORE you exit the scope, thus the render window and all its connected stuff will still be in memory.

So either you missed some C++ basics or I don't understan what _CrtDumpMemoryLeaks(); does.

PS: You can use 'code=cpp' to highlight your code and for one-liners there's the tag 'tt'. ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Roose Bolton of the Dreadfort

  • Full Member
  • ***
  • Posts: 113
  • Full-time Procrastinator, Part-time programmer.
    • View Profile
    • Personal Portfolio/Website/Blog
Re: Memory Leaks.. no idea where its coming from!
« Reply #5 on: May 31, 2012, 02:32:55 am »
Right.. but think, if I used it AFTER the return, it would never get called - Correct?

The way I have implemented it is the same way its done on MSDN and multiple resources - so I assumed it was correct - not because I don't understand C++

also; as you can see, if the close event runs, window.close() is called which I assume is the renderwindows clean up method; which would be called before the end of the scope

Code: [Select]
// Close window : exit
 if (event.type == sf::Event::Closed)
window.close();

I probably am doing it wrong - I just want to make sure its SFML and me being dumb!

Thanks,

Matthew
« Last Edit: May 31, 2012, 07:11:20 am by 1337matty »
Trying so very hard to finish at-least one project.

Watch out for the RAII police, they will get you.

www.bantersaurus-games.com

Roose Bolton of the Dreadfort

  • Full Member
  • ***
  • Posts: 113
  • Full-time Procrastinator, Part-time programmer.
    • View Profile
    • Personal Portfolio/Website/Blog
Re: Memory Leaks.. no idea where its coming from!
« Reply #6 on: May 31, 2012, 07:28:42 am »
this is what is popping up in the call stack >

http://imgur.com/IYDt7
« Last Edit: May 31, 2012, 07:31:43 am by 1337matty »
Trying so very hard to finish at-least one project.

Watch out for the RAII police, they will get you.

www.bantersaurus-games.com

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Memory Leaks.. no idea where its coming from!
« Reply #7 on: May 31, 2012, 07:56:18 am »
You should forget about that, they are most likely not true leaks.
Laurent Gomila - SFML developer

Roose Bolton of the Dreadfort

  • Full Member
  • ***
  • Posts: 113
  • Full-time Procrastinator, Part-time programmer.
    • View Profile
    • Personal Portfolio/Website/Blog
Re: Memory Leaks.. no idea where its coming from!
« Reply #8 on: May 31, 2012, 10:15:42 am »
Thanks Laurent :D

Back to work for me!

Trying so very hard to finish at-least one project.

Watch out for the RAII police, they will get you.

www.bantersaurus-games.com

Acrobat

  • Full Member
  • ***
  • Posts: 153
    • View Profile
Re: Memory Leaks.. no idea where its coming from!
« Reply #9 on: May 31, 2012, 11:20:19 am »
i'm testing with this code, and there is no leaks (in my project)

int main ()
{
#ifdef _DEBUG
        _CrtSetDbgFlag( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
        _CrtSetReportMode( _CRT_ERROR, _CRTDBG_MODE_DEBUG );
#endif
// other code
}
 

 

anything