Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SDL Events Memory Leak

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
like image 762
Benjamin Avatar asked Apr 07 '26 09:04

Benjamin


2 Answers

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

like image 111
Quetzy Garcia Avatar answered Apr 09 '26 23:04

Quetzy Garcia


valgrind --track-origins=yes --leak-check=full --show-reachable=yes ./executable
like image 39
Gino Avatar answered Apr 10 '26 00:04

Gino



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!