Hi,
I have observed a mysteries behavior in the following program on Red
Hat Linux 8.0.
I am allocating 24MB memory and freeing it.
The processes memory grows up to 24MB and it stays there even if I
free the memory in "ReleaseMemoryL()" function.
But if I remove the line "MemList.push_back(i);", the program works
fine.
Can anybody help me to sort out this problem?
TIA,
Ramki
#include <stdlib.h>
#include <ctype.h>
#include <stdio.h>
#include <list>
#include <iostream>
#include <fstream>
using namespace std;
const int LOOP = 24000;
const int SIZE = 1024;
typedef list<int > Deque;
Deque MemList;
char *CharArray [LOOP];
void AllocMemoryL()
{
for (int i=0;i<LOOP;i++)
{
char *mem = new char[SIZE];
MemList.push_back(i);
CharArray[i] = mem;
}
}
void ReleaseMemoryL()
{
for (int i=0;i<LOOP;i++)
{
delete [] CharArray[i];
}
MemList.clear();
}
int main(int argc, char const * argv[])
{
cout<<"Allocating memory"<<endl;
AllocMemoryL();
cout<<"Allocated memory successfully"<<endl;
char ch;
cin>>ch;
cout<<"Releasing memory"<<endl;
ReleaseMemoryL();
cout<<"Released memory successfully"<<endl;
cin>>ch;
return 0;
}
|