'How to delete a heap allocated std:::array

I have this pointer in a class:

std::array<std::array<std::array<Item*, XSize>, YSize>, ZSize>* Items;

In the constructor:

Items = new std::array<std::array<std::array<Item*, XSize>, YSize>, ZSize>();

In the class descructor i have tried calling

delete Items;
delete[] Items;

but there is a memory leak in my program when i constantly create and delete this type of class



Solution 1:[1]

The code you provided did not detect a memory leak. In additionif delete[] is used, an obvious warning will occur:

Warning C6279 'Items' is allocated with scalar new, but deleted with array delete[]

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Remy Lebeau