So what happens to a pointer if you release an object owned by auto_ptr but do not actually assign it to a raw pointer? It seems like it’s supposed to be deleted but it never gets the chance to. So does it get leaked out “into the wild”?
void usingPointer(int* p);
std::auto_ptr<int> point(new int);
*point = 3;
usingPointer(point.release());
Note: I don’t use auto_ptr anymore, I use tr1::shared_ptr now. This situation just got me curious.
releaseisn’t suppose to delete the owned point, from the docs:Also, it’s overkill to replace all uses of your
auto_ptrwithtr1::shared_ptr– you should be usingunique_ptrwhere a shared one isn’t necessary.