且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用STL容器的C ++内存泄漏

更新时间:2023-02-12 11:27:57

程序退出时,向量 被销毁,您不需要确保它。您需要确保 _CrtDumpMemoryLeaks 在销毁后被调用,如果您不希望将分配的内存报告为leaked:

The vector is destroyed when the program exits, you don't need to ensure it. You do need to ensure that _CrtDumpMemoryLeaks is called after that destruction if you don't want it to report the allocated memory as "leaked":

int main()
{
    { Subject subject; }
    _CrtDumpMemoryLeaks();
    return 1;
}