SFML community forums

Help => Graphics => Topic started by: Grimshaw on February 29, 2012, 02:33:32 am

Title: Possible memory leak
Post by: Grimshaw on February 29, 2012, 02:33:32 am
Hello,

Recently I noticed a memory leak in my applications, so I tried to track it down and I think there is something wrong with two SFML functions.

So, my applications were simply ALWAYS allocating memory. Like 4KB/s, by watching the task manager.

I started to look for the problem, and i narrowed it down to this piece of code:

Code: [Select]
if(myWindow && activeDrawing){
myWindow->SetActive(true);
myWindow->Clear(clearColor);
onRender();
myWindow->Display();
}


That is my "render loop". If i comment those 4 lines,the memory does not increase at all.

Otherwise, it goes nuts. Clear() doesn't seem to do harm, however, Display() is consuming the most. SetActive() is also consuming memory from time to time, but way less than Display().

Can you please discuss this?

EDIT: I was unable to reproduce the problem with a minimal application, therefore i don't really understand why that couple of functions are having that effect while commenting them actually works, in the context of the other app.
Title: Possible memory leak
Post by: Tex Killer on February 29, 2012, 03:09:37 am
How is your onRender function?
Title: Possible memory leak
Post by: Grimshaw on February 29, 2012, 03:23:49 am
empty, as i was just looking for the problem..
Title: Possible memory leak
Post by: Tex Killer on February 29, 2012, 06:00:01 am
Try making a copy of your project and removing a part of the other code (not the one that you posted here) at a time, checking if the leak remains. That way you will have either a minimal example code for us or the solution.
Title: Possible memory leak
Post by: Laurent on February 29, 2012, 08:00:08 am
It might be a problem with the graphics driver. You're not the first one to report such a leak, and we could never find anything in SFML.
Title: Possible memory leak
Post by: Grimshaw on February 29, 2012, 12:27:47 pm
Its really weird, I did comment all my code by parts, just until i could narrow the leak down to one function..

Commenting those lines does solve it, and the code im running is as simple as it gets in my framework, nothing special is happening in it.

However a simple sfml snippet works..

I did have a Nvidia crash yesterday. In one of the runs when i was tracking the issue, the memory consumption increased suddenly by a few MB and i got a black screen. After that, I could see a error:

Nvidia graphics driver connection with the software was lost, therefore the application must be closed. (Something like this)

And then everything went back to normal..

I bet its related to initializing other libraries too, but I need more testing and I can't right this time :)