I am very confused about this simple code. why this code can release the memory allocated.
double *a;
for(int i = 0 ; i < 1000000 ; i++)
{
if(1){
a = new double ;
}
if(1){
delete a;
}
}
but this code can not remove all memory allocated.
std::vector<double *>rubberList ;
for(int i = 0 ; i < 1000000 ; i++)
{
rubberList.push_back(new double);
//delete rubberList[i];
}
for(unsigned long j = 0 ; j < 1000000 ; j++)
{
delete rubberList.at(j);
}
and when delete items in the allocator block correctly remove the memory.
for(int i = 0 ; i < 1000000 ; i++)
{
rubberList.push_back(new double);
delete rubberList[i];
}
tnx