0
Visual Studio 2012告訴我下面的程序有內存泄漏。這是正確的,如果是這樣的話,當使用(例如)靜態向量時如何避免內存泄漏?靜態變量導致C++內存泄漏
#include <crtdbg.h>
#include <vector>
struct A {
static std::vector<int> a;
};
std::vector<int> A::a;
int main()
{
_CrtDumpMemoryLeaks();
return 0;
}
它報告「泄漏」,因爲你稱它爲時尚早。如果您刪除對_CrtDumpMemoryLeaks的調用並在Debug中運行,是否會收到泄漏報告? –
@RogerRowland糾正我,如果我錯了,但不是那個調用需要產生內存泄漏報告? – DeeperUnderstanding