The SDL forums have moved to
This is just a read-only archive of the previous forums, to keep old links working.
Simple Directmedia Layer Forums
SDL2 OPENGL SDL_RENDERER_ACCELERATED MEMORY LEAK
Joined: 11 Nov 2016
Posted: Mon Nov 14, 2016 2:14 pm
I had a huge memory leak when using SDL_RENDERER_ACCELERATED for creating an SDL_Renderer in Ubuntu 16.04-64Bits.
The leak was shown in the System Monitor but was not detected by Valgrind.
When I replaced SDL_RENDERER_ACCELERATED flag with SDL_RENDERER_SOFTWARE flag, the memory leak disappeared.
The reason to use RENDERER_ACCELERATED flag is that it made our application run faster in displaying images continuously.
Here is a simple C program to demonstrate the issue.
int main(int argc, char* argv)
SDL_Init(SDL_INIT_VIDEO); // init video
SDLWin = SDL_CreateWindow("SDL2 Example", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 60, 40, SDL_WINDOW_OPENGL);
//SDLWin = SDL_CreateWindow("SDL2 Example", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 60, 40, 0); //changing the flag from SDL_WINDOW_OPENGL to 0 does not eliminate the memory leak
SDL_Renderer* SDlRenderer = SDL_CreateRenderer(SDLWin, -1, SDL_RENDERER_ACCELERATED ); //cause a huge memory leak!
//SDL_Renderer* SDlRenderer = SDL_CreateRenderer(SDLWin, -1, SDL_RENDERER_SOFTWARE); //no memory leak
switch( event.type )
printf("event type = %d\n", event.type);
INCLUDES = -I/usr/include/SDL2
CFLAGS = -g -Wall -Werror -std=c11 $(INCLUDES)
LD = gcc
LDLIBS = -L/usr/lib/x86_64-linux-gnu -lSDL2
SOURCES = main.c
OUT = sdl_opengl
$(OUT): $(patsubst %.c,%.o,$(SOURCES))
$(LD) $(LDFLAGS) -o $@ $? $(LDLIBS)
rm *.o $(OUT)
Joined: 06 Jan 2017
Posted: Fri Jan 06, 2017 8:44 pm
I am experiencing the same.
Did you try to measure the memory consumption? Will it just keep growing beyond any limits?
© phpBB Group
Content © SDL