We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 5377

Summary: Memory leak in SDL_RenderCopy
Product: SDL Reporter: Miguel Dorta <dortamiguel>
Component: renderAssignee: Sam Lantinga <slouken>
Status: WAITING --- QA Contact: Sam Lantinga <slouken>
Severity: critical    
Priority: P2    
Version: 2.0.13   
Hardware: x86_64   
OS: macOS 10.15   
Attachments: The code that reproduces the memory leak when using SDL_RenderCopy

Description Miguel Dorta 2020-12-02 10:24:01 UTC
I found a huge memory leak in SDL_RenderCopy when doing more than 100k calls.

Basically I’m drawing a grid with a lot of tiles.

If I draw in a loop this grid the memory stays at 120mb but if translate the coordinates of each tile with an offset, as soon as the grid stars to get drawn outside of the window viewport, then the memory grows and grows every frame taking all system memory.

As soon as the program stops moving the grid the memory usage stops increasing but the leaked memory is not released.

Also when the grid goes completely outside of the viewport the memory leak stops.

I attached a main.c file with the code to reproduce this bug.
Comment 1 Miguel Dorta 2020-12-02 10:26:16 UTC
Created attachment 4554 [details]
The code that reproduces the memory leak when using SDL_RenderCopy
Comment 2 Sam Lantinga 2020-12-20 20:24:37 UTC
I just tried to reproduce this on macOS and wasn't able to. Are you still seeing this with the latest snapshot?
http://www.libsdl.org/tmp/SDL-2.0.zip