简体   繁体   中英

SDL2 memory leaks on SDL_DestroyRenderer

This code will explain the plot:

// on init:

m_mainWindow = SDL_CreateWindow("title", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 480, 640, SDL_WINDOW_SHOWN);
m_mainRenderer = SDL_CreateRenderer(m_mainWindow, -1, 0); // + 8 Mb of memory

// on screen resize when my ios sends SDL_WINDOWRESIZED:
SDL_DestroyRenderer(m_mainRenderer); // - 1!!! Mb of memory

m_mainRenderer = SDL_CreateRenderer(m_mainWindow, -1, 0); // + 6 Mb of memory

I can't fully destroy renderer and clear memory of it. why? and what I did wrong here?

You don't need to create a Renderer at each Resize, your renderer size will be updated automatically... Basically, you can do everything in your software with ONLY ONE renderer. By the way, the SDL_Renderer doesn't contains dimension attributes, the windows contains it and the SDL_Renderer is linked to that Window

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM