The smart pointer will be destroyed at the end of the program as all other objects. So when the destructor is called the pointer will be deleted. Her you get an example which is not even close to a real smart pointer, but it gives the idea:
#include <iostream>
using namespace std;
template <typename T>
struct example {
T* p_;
example(T* p): p_{p} {
cout << "example(T* p)\n";
}
~example() {
cout << "~example()\n";
delete p_;
}
};
int main() {
cout << "start main\n";
example<int> p{new int};
cout << "end main\n";
return 0;
}
Try it out here: https://ideone.com/rOtQY9
Anyway, the use of a global smart pointer eludes me. The program is finished so the memory would have been released to the OS anyway. The nice thing is that whatever resource has been acquired during construction will also be released for sure (e.g. a file could be closed correctly, or a bitstream buffer could be flushed).