We have code like this:
void main(){
std::list<int *> ll;
for(int i=0;i<100;i++)
{
int *a = new int[10000];
ll.push_back(a);
}
for(int *b : ll)
{
delete [] b;
}
ll.clear();
}
But the memory not free? Why? When run this code work correctly:
void main(){
for(int i=0;i<100;i++)
{
int *a = new int[10000];
delete [] a;
}
}
I monitor memory with top command in linux and system monitoring, so in first code in first for the memory was going up and after that i expect that in last for the app free the memory but not free memory.