VRAM gets filled but not released

while testing my game i noticed in MSI Afterburner (a program that shows stats like FPS, CPU and GPU usage and temps, RAM and VRAM usage…) that my VRAM was filling up but never went down again. It took me quite a while to figure it out, but the following shows the problem the best i could. Basically you can see my main loop, that’s creating a texture, setting it as the rendering target and then destroying it each frame. This texture grows in size each frame until it has a size of 1000x1000.


int w = 1;
int h = 1;
SDL_Texture* texture = NULL;
while (run) {
SDL_SetRenderDrawColor(renderer, 200, 200, 200, 255);
if (w <= 1000 && h <= 1000) {
w += 1; //no “leak” with fixed size
h += 1; //no “leak” with fixed size
texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, w, h);
SDL_SetRenderTarget(renderer, texture); //no “leak” when commented out
//in my real game I’m rendering here something onto the texture
SDL_SetRenderTarget(renderer, NULL);

This fills my VRAM to about 1.9 GB in less than a second, even though the textures get destroyed immediately. After the texture reaches the size of 1000x1000 it gets destroyed one last time inside the if block and afterwards the if block never gets called again, but the VRAM stays at about 1.9 GB.

This problem doesn’t exist (VRAM stays at 400 MB) if I just keep creating and destroying a texture with a fixed size of 1000x1000 or by commenting out the line, where I set the newly created texture as the rendering target, which is really confusing to me.

So is there something wrong with the code above or is this behavior intended?