F
fishscience
I have a problem about memory usage. The code is as below:
#include <list>
int main(int argc, char* argv[])
{
{
std::list<void*> ptr_list;
{
for (int i=0; i<9368; i++)
{
size_t size = 10044;
void* p = ::malloc (size);
ptr_list.push_back (p);
}
for (std::list<void*>::iterator i=ptr_list.begin(); i!= ptr_list.end();
i++)
{
void* p=(*i);
::free (p);
}
}
ptr_list.clear();
}
return 0;
}
When all elements in list are freed, the application still have about 30M
memory. After clear function is called, most of memory is freed. However,
the application will have 300k more than the beginning. I think all
allocated memory should be released after list is cleared. The question
is:
1. Why does list still have 30M even if all elements are freed?
2. Why does this program take up 300k more than the beginning?
Test environment:
Windows XP
VS 2005
#include <list>
int main(int argc, char* argv[])
{
{
std::list<void*> ptr_list;
{
for (int i=0; i<9368; i++)
{
size_t size = 10044;
void* p = ::malloc (size);
ptr_list.push_back (p);
}
for (std::list<void*>::iterator i=ptr_list.begin(); i!= ptr_list.end();
i++)
{
void* p=(*i);
::free (p);
}
}
ptr_list.clear();
}
return 0;
}
When all elements in list are freed, the application still have about 30M
memory. After clear function is called, most of memory is freed. However,
the application will have 300k more than the beginning. I think all
allocated memory should be released after list is cleared. The question
is:
1. Why does list still have 30M even if all elements are freed?
2. Why does this program take up 300k more than the beginning?
Test environment:
Windows XP
VS 2005