- 论坛徽章:
- 0
|
请教大家一个问题
#include <list>
#include <string>
using namespace std;
typedef list<string> mylist;
int main()
{
mylist m_mylist;
char sql[1024]={0};
int i=0,n=0;
for(i=0;i<10000;i++)
{
sprintf(sql,"sql-%01024d",i);
printf("sql=%s\n",sql);
m_mylist.push_back( sql );
}
printf("m_mylist.count=%d\n",m_mylist.size());
printf("add over..\n");
sleep(10);
mylist::iterator iter;
string str;
iter = m_mylist.begin();
while(iter != m_mylist.end())
{
str = *iter;
printf("str =%s\n",str.c_str() );
m_mylist.erase(iter);
iter = m_mylist.begin();
}
printf("disp over..\n");
printf("m_mylist.count=%d\n",m_mylist.size());
sleep(1000);
return 0;
}
|
我的这段代码,在win下能正常释放内存,在linux下却不能释放,是怎么回事?
我用的不对吗?
m_mylist.erase(iter);这个删除怎么不释放内存呢?
谢谢呀,耽误大家时间了. |
|