I have a structure "Indices" containing buffer for indices (DirectX, but I think it doesn't matter):
struct Indices {
CComPtr<ID3D11Buffer> buffer;
UINT indexCount;
};
and a method which initializes array with objects of class Indices:
mIndices = new Indices*[layers];
for( int i = 0; i < layers; ++i )
mIndices[i] = new Indices[corrections];
//... initializing buffers
and method which frees memory:
for( int i = 0; i < layers; ++i )
delete mIndices[i]; // here I am getting critical error
delete mIndices;
but when I try to release the memory I am getting "Critical error detected c0000374" (pointed out in the code above).
Could you help me, please? I hope the posted code will be enough to solve my problem.
Thanks
When you create arrays with new T[n], you also have to use delete[] to release the memory:
for( int i = 0; i < layers; ++i )
delete[] mIndices[i];
delete[] mIndices;
Manual memory management is a hazzle, leading easily to crashes and memory leaks. Have you considered std::vector? It can be used as a drop-in replacement for dynamic arrays:
// create and initialize the arrays
std::vector< std::vector<Indices> > indices(layers, std::vector<Indices>(corrections));
// will be automatically freed when lifetime ends
Since you are allocating arrays, you should be deallocating arrays. Use delete[] instead of delete.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With