Big memory problem, growing increase !

Hi,

I am very surprised to realize that with just the basic skeleton of a C program with SDL, my application devours 5MB RAM every 1 second.
So after a few minutes my RAM is FULL

Where is the problem ?

For the test, no control on function returns, no waiting for an event, but my window works fine!
(I kick it with vscode), here is my code, the minimum :

#include <SDL.h>
#include <stdio.h>
#include <stdlib.h>

int main(int argc, char **argv){

    if (!SDL_Init(SDL_INIT_VIDEO)){

        SDL_Window * pWindow = SDL_CreateWindow("Linux SDL",
            SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 600, 400, SDL_WINDOW_SHOWN);

        if (pWindow != NULL){
      
            SDL_Renderer * pRenderer = SDL_CreateRenderer(pWindow, -1, SDL_RENDERER_ACCELERATED);

            while (1){

                SDL_RenderClear(pRenderer); 
                SDL_RenderPresent(pRenderer);

            } 
            
            SDL_DestroyRenderer(pRenderer);
            SDL_DestroyWindow(pWindow);
            SDL_Quit();

            return EXIT_SUCCESS;
        }
    }

    return EXIT_FAILURE;
}

And my arguments vscode of compilation C :

"args": [
                "-fdiagnostics-color=always",
                "-Wall",
                "-O3",

                "-I/usr/include/SDL2",
                "-D_REENTRANT",
                "-L/usr/lib",
                "-Wl,-rpath,/usr/lib",
                "-Wl,--enable-new-dtags",
                "-pthread",
                "-lSDL2",
                "-lSDL2_ttf",
                
                "-g",
                "${file}",
                
                "-o",
                "${fileDirname}/${fileBasenameNoExtension}"
            ],

My OS : Linux Manjaro

Thank you for your ideas … I imagine that for a lib like SDL this is not normal! :slight_smile:

I don’t know, but there’s nothing to limit the speed at which it runs the rendering loop so it’s an entirely unrealistic situation. What happens if you specify SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC in the SDL_CreateRenderer() flags?

Oh very nice ! It works !

I just add SDL_RENDERER_PRESENTVSYNC and the memory is stabilized !

I don’t understand this parameter is vague ind the documentation. Why this and not another ?

Synchronizes rendering with refresh rate. The refresh rate is the number of times the screen is updated per second. Thus, the rendering will be synchronized with it.

Thank you @rtrussell