Are there any know methods or functions in SDL known to cause memory leaks?
I noticed for my program that as time when on, .1 MB of memory kept on being tacked onto the program's memory usage (ie. an extra '.4 MB' were added in exactly 3 minutes).
I commented out all of my surface drawing/bliting functions; pretty much just isolated the main game loop to the event structure and screen flipping, ex:
// .. Intilize
char quit = 0;
Uint8* keystate = NULL;
SDL_Event hEvent;
while (!quit)
{
// .. Code
while (SDL_PollEvents(&hVvent)) {
keystate = SDL_GetKeystate(NULL);
// .. Event processing
}
// .. More Code
if (SDL_Flip(screen) == -1)
return 1
SDL_Delay(1);
}
// .. Cleanup
My favourite tool to check for memory leaks is Valgrind. After compiling your code, just run the following command:
valgrind --leak-check=full --show-reachable=yes ./executable
After finishing, check the output for memory leak information. The tool can be more verbose, by issuing the -v flag
valgrind --track-origins=yes --leak-check=full --show-reachable=yes ./executable
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With