I have a memory issue, it seems that if I load a texture with the below function and then use SDL_DestroyTexture(texturename); followed by texturename= nullptr; to release it, the system memory used is not released. What am I doing incorrectly?
That block is the failure block and is a little confusing. On failure, you may prefer to return NULL so you can detect failure and respond appropriately. As it is, you instead get a dummy texture that is not even the size you expected.
This creates a new texture, then returns it, ending processing of this function. The rest that follows the return is unreachable code. The texture and surface are not freed. You do not really want to free the texture here anyhow, as the whole point of the function is to get a valid texture. If you destroy the texture, it won’t be valid any more.
You’re probably doing something like SDL_Texture* pMyTexture = LoadTexture("ImageFile.png");
so it’s up to you to, at shutdown of the application, execute SDL_DestroyTexture(pMyTexture); to free the memory allocated by your LoadTexture function.
Naith, that is what I am and have been doing, Everything that is created is either SDL_Destroy()'ed or SDL_Free()'ed on close. I found the secondary issue with the memory leak was no longer apparent nor detected in Dr Memory when the application is limited to 60 FPS. If I let it run unthrottled, Dr memory cites the Nvida driver as the leak. Also this utility is how I found the first leak to be in my code.