[英]How does share_ptr release memory when main ends?
It is said that this is related to threads, I don't know much about OS.Thanks for your Answers.据说这与线程有关,我对操作系统不太了解。感谢您的回答。
int main(){
shared_ptr<int> p = make_shared<int>(1024);
//do nothing,end my program
}
use_count() will be 1 if I check in main,how to be 0?Or wo need to release operation.如果我签入main,use_count() 将为1,怎么为0?或者我需要释放操作。
Nothing to do with the OS, the shared_ptr
destructor frees the memory and since p
is a local variable the scope will end (ie call destructor) when main ends.与操作系统无关,
shared_ptr
析构函数释放 memory 并且由于p
是局部变量 scope 将在 main 结束时结束(即调用析构函数)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.