I'm currently getting myself into c++ for lower level coding with opengl. I come from a heavy objc background so I have some understanding about memory management but I can't seem to get how the "boost" library manages container types like ptr_vector
.
I think my problem is related to the fact that I have no idea how ptr_vector
manages the destruction of itself and its objects.
Please take a look at the following code:
// Header file
...
ptr_vector<IObject3D> objects;
...
// Implementation file
...
void ApplicationEngine::init()
{
WavefrontObject3D *object = new WavefrontObject3D("Ninja.obj");
objects.push_back(object);
}
...
So, for the actually question: am I creating a leak here through the "object" variable?
I'm used to retain and release my objects manually with explicit calls in objc:
previously I had to alloc init
the WavefrontObject3D object
, add it to an array and afterwards release
that same object to avoid leaks.
But when I add a delete object
after the push_back
call the deconstructor of the WavefrontObject3D object
is called. This gives me a hint that the ptr_vector
isn't retaining the object
variable. Is my assumption correct?
Additional, but related, question: let's say I want to destroy the containing class ApplicationEngine
don't I have to call some kind of deconstructor on the ptr_vector
or the elements it manages?