SFML community forums

Help => Network => Topic started by: zac on February 03, 2009, 03:42:29 pm

Title: Massive Memory Leak
Post by: zac on February 03, 2009, 03:42:29 pm
There is a leak in heap memory, either in the classes Http or in one of the underlying classes. I am not using new or delete (despite for one single new/delete on begin/end of the program) in my program (downloading musics from lastfm), but it starts to use more and more heap space (memory field is heap). After ~200 MB of transferred data it uses ~40 MB ram (it begins with 2,2 MB)...
But I can't see where in the Http class it could be -.- all you use are C++-STL classes, I think.
I'll recheck my own code again and see if I can find a reason in there...

Ah:
I think I see now, it has most propably to do with the system cleaning up the memory allocated for the sockets or something similar, because the memory usage drops all of a shudden after reaching a high level (~50 MB) back down to ~6 MB. Seems very strange to me.
Title: Massive Memory Leak
Post by: Nexus on February 03, 2009, 04:20:02 pm
The OS does mostly not deallocate the memory instantly.

If you wait long enough, everything is freed again? For example, you could use a memory leak detector...
Title: Massive Memory Leak
Post by: zac on February 03, 2009, 07:29:08 pm
It is okay like that... I think everything is freed as it should be, but with a little delay...
But 50 MB is clearly way bigger than the data downloaded at once^^ ;)
But it is hard to tell if everything is freed because the program surely does not stop downloading...
But for this small project (the code is definitely a quite dirty hack) that I will mainly use for myself it is absolutely okay.
Title: Massive Memory Leak
Post by: Tank on February 04, 2009, 01:35:00 pm
That's what memory is for. :) Like Nexus said, operating system's memory managers mostly make high usage of memory caches. Instantly freeing and allocating memory would result in speed penalties. So as long as the proper memory is available, it'll be used as a cache, thus increasing performance.

You may want to checkout your program's memory usage when you're low on RAM. It shouldn't allocate too much of memory, then.