我unique_ptr用作静态数据成员来保存指针.
struct Test
{
int i;
~Test()
{
cout << "destructed" << endl;
}
};
struct S
{
static unique_ptr<Test> te;
};
unique_ptr<Test> S::te = unique_ptr<Test>(new Test());
Run Code Online (Sandbox Code Playgroud)
程序终止S::te被破坏,调用Test-destructor.
但_CrtDumpMemoryLeaks向我显示内存泄漏,其内存位置S::te.get()是指向(破坏的)Test对象的指针.
我不明白这种行为.
我不能用静电unique_ptr吗?尽管unique_ptr实现调用析构函数,为什么会出现泄漏?