> >>>>> "Michael" == Michael Mwangi <mwangi@xxxxxxxxxxxxxxxxxxxxx> writes: > > Michael> Using top, I monitored memory usage and noticed the > Michael> delete operation did not free the 24 MB allocated by the > > That simply means that the memory is not returned to the kernel. > Nevertheless, it is still available for allocation by the same process > and is eventually returned to the kernel when the process exits. > > ~velco Thank-you very much for your quick response. I need but ask one more question for clarification. A set containing a 1000000 longs and a vector containing 6000000 longs each take about 24 MB. Consider the following two programs: #include <set> int main() { set<unsigned long> *s1 = new set<unsigned long>(); set<unsigned long> *s2 = new set<unsigned long>(); unsigned long i; for(i = 1; i <= 1000000; i++) { (*s1).insert(i); } (*s1).clear(); delete s1; for(i = 1; i <= 1000000; i++) { (*s2).insert(i); } while(1); } #include <set> #include <vector> int main() { set<unsigned long> *s1 = new set<unsigned long>(); vector<unsigned long> *v1 = new vector<unsigned long>(); unsigned long i; for(i = 1; i <= 1000000; i++) { (*s1).insert(i); } (*s1).clear(); delete s1; for(i = 1; i <= 6000000; i++) { (*v1).push_back(i); } while(1); } When I compiled and ran the first program and monitored memory usage using top, I as I expected observed that the program in total used 24 MB. Hence, it appears that the 24MB allocated for the first set are made available by de-allocation using delete for the second set. The second program however uses in total 48 MB. Hence, the 24 MB allocated for the set is not made available using delete for the subsequent vector. You stated above: "That simply means that the memory is not returned to the kernel. Nevertheless, it is still available for allocation by the same process." In this context, the same process are operations on the set class. Operations on the vector class constitute a different process. Thus, if you allocate a large amount of memory in a program for a set and the delete the set, it will not be avaliable for anything else but filling another set. If all subsequent operations involve objects of classes other than set, the memory is essential lost to your program. Am I right, or is there a way around this? Mike