struct Vertex
{
short v[2];
};
struct VertexInfo
{
Vertex* vertex;
int _vertexCount;
};
I create an instance of Vertex info within a function and save the pointer in a global(batch).
VertexInfo* batch = new VertexInfo;
Now here is my question...
When I allocate a dynamic array in batch->vertex and at a later point delete batch, does that mean that the array(within batch) 'vertex' is freed also(since its a child of batch)?
Or do I have to delete vertex first, then delete batch?
You have to delete vertex first, then batch. C++ does not handle your deletes so whenever you declare space of the heap, you better delete it somewhere, no matter how deep the allocation is in your structures.
So, even though VertexInfo has been put on the heap, I have to iterate any pointers within VertexInfo that have been allocated memory too? I assumed that if a parent on the heap gets deleted, then all child structures would too? I think I may be expecting too much from the heap manager.
Please excuse me for reiterating my question as I am trying to clear it up in my own head.
Nah, it's not that easy in C++. There is ZERO garbage cleanup. Every single bit of memory you allocate in the heap needs to be explicitly deleted somewhere.