I was wondering if anyone could help me to sort out a bit of confusion I have with unique pointers. Consider the following code:
// some class "complex" defined here
int main()
{
while(1)
{
unique_ptr<complex> p(new complex[256]);
p.reset();
}
return 1;
}
Now from what I understand, when I invoke reset() on the unique pointer it should delete the object that its raw pointer is referring to. In this case, the object happens to be the very first object of type complex out of 256 created. Because that's what new complex[256] does, am I right? It simply returns a pointer to the first object in the array (which it, of course, also creates)? So the rest of 256 objects should remain untouched.
Following that logic, the infinite loop should create a memory leak, but that does not happen. I am using MS Visual Studio 2013.
What am I missing? I would be very grateful if anyone could fill me in on what's happening here and confirm or disapprove my conjectures :)
Best, Dikey
Aucun commentaire:
Enregistrer un commentaire