Use for cleaning
data.clear();
This will remove all pointers from the vector. If any of them are the only copies that point to their respective dynamic objects, then these objects can no longer be destroyed and their memory can not be freed. This is called a memory leak.
Or you need to delete all new (s)
Yes. Each time the expression new[]
must be exactly one delete[]
. If not delete[]
, then there is a leak.
, ?
. , , . , ( ) .
void
. void , .
delete[] static_cast<double*>(data[0]);
delete[] static_cast<short* >(data[1]);
, , , - , void
. - RAII, std::vector
:
std::vector<double> doubles(1024);
std::vector<short> shorts (1024);
std::vector<void*> data{doubles.data(), shorts.data()};
, , std::vector
. , doubles
shorts
, data
.