【问题标题】:Why does a simple SDL program report memory leaks in Valgrind?为什么一个简单的 SDL 程序会在 Valgrind 中报告内存泄漏?
【发布时间】:2014-08-19 22:48:17
【问题描述】:

这个程序:

#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

这是我应该担心的事情吗?如果是,我如何知道代码中误报和实际错误之间的区别?

【问题讨论】:

标签: c++ memory-leaks sdl valgrind


【解决方案1】:

取自stackoverflow answer


在您的具体情况下,我会使用标志 --leak-check=full --track-origins=yes --show-reachable=yes 运行 valgrind,看看泄漏是否真的来自 SDL

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-11-11
    • 1970-01-01
    • 2011-01-01
    • 2019-03-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多