In the code example below, the function “_CrtDumpMemoryLeaks” prints in the console any objects that causes memory leaks. According to this tool, SDL_Quit doesn’t clean all the object SDL_Init creates. Does this mean I also need to call another function to clean these objects, or is this just a false positive of _CrtDumpMemoryLeaks (this function is called before the destruction of global objects).
#include <iostream>
#include <SDL.h>
int main(int argc, char* argv[]) {
// Checks for memory leaks when using MSVC compiler
_CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_FILE);
_CrtSetReportFile(_CRT_WARN, _CRTDBG_FILE_STDOUT);
_CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_FILE);
_CrtSetReportFile(_CRT_ERROR, _CRTDBG_FILE_STDOUT);
_CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_FILE);
_CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDOUT);
if (SDL_Init(SDL_INIT_VIDEO) < 0)
{
printf("Could not initialize SDL. SDL_Error: %s\n", SDL_GetError());
return EXIT_FAILURE;
}
SDL_Quit();
_CrtDumpMemoryLeaks();
return EXIT_SUCCESS;
}
The console output is as follows:
Detected memory leaks!
Dumping objects ->
{145} normal block at 0x000002466CBC4110, 132 bytes long.
Data: < > 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
{144} normal block at 0x000002466CBBE200, 88 bytes long.
Data: < A lF > 05 00 00 00 CD CD CD CD 10 41 BC 6C 46 02 00 00
Object dump complete.
Process finished with exit code 0