这个程序:
#include <iostream>
#include <SDL2/SDL.h>
/*
* Lesson 0: Test to make sure SDL is setup properly
*/
int main(int argc, char** argv){
if (SDL_Init(SDL_INIT_EVERYTHING) != 0){
std::cout << "SDL_Init Error: " << SDL_GetError() << std::endl;
return 1;
}
SDL_Quit();
return 0;
}
使用
g++ -o main main.cpp -lSDL2; valgrind ./main
编译会产生以下输出:==21646== HEAP SUMMARY:
==21646== in use at exit: 108,320 bytes in 582 blocks
==21646== total heap usage: 16,412 allocs, 15,830 frees, 106,043,200 bytes allocated
==21646==
==21646== LEAK SUMMARY:
==21646== definitely lost: 12,058 bytes in 4 blocks
==21646== indirectly lost: 0 bytes in 0 blocks
==21646== possibly lost: 0 bytes in 0 blocks
==21646== still reachable: 96,262 bytes in 578 blocks
==21646== suppressed: 0 bytes in 0 blocks
这是我应该担心的事情吗?如果是这样,我如何知道我的代码中的误报与实际错误之间的区别?
最佳答案
取自此stackoverflow answer
在您的特定情况下,我将使用标志--leak-check=full --track-origins=yes --show-reachable=yes
运行valgrind,看看泄漏是否真的来自SDL。