简体   繁体   中英

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM