I realized that after calling vector.clear() which hold shared pointers, the destructors of the object which own by shared_ptr is not being released. <
The reason the destructor isn't called until later is that your variable sharedptr is still in scope until the end of your main(). There are a few ways around this if you really want it cleaned up before then. The most obvious way to fix this is to only use sharedptr in a quick block scope:
int main( )
{
std::vector > test;
{
shared_ptr sharedptr (new A);
test.push_back(sharedptr);
}
test.clear();
cout << "I am here" << endl;
}
Or alternatively, never create the sharedptr variable at all:
int main( )
{
std::vector > test;
test.push_back( shared_ptr(new A) );
test.clear();
cout << "I am here" << endl;
}