Skip to main content

What is Why does the free() function logicnot return memory to the operating system?

When iI use the top terminal program at linuxLinux, iI can't see the result of free.

My expectation isMy expectation is:

  1. free map and list.

  2. The memory usage that iI can see at the top(linuxLinux function) or /proc/meminfo/proc/meminfo get smaller than past.

  3. sleep is start.

  4. program exit.

But The usage of memory only getgets smaller when the program is endends.

Would you explain the logic of free function?

Below is my code.

for(mapIter = bufMap->begin(); mapIter != bufMap -> end();mapIter++) { list<buff> *buffList = mapIter->second; list<buff>::iterator listIter; for(listIter = buffList->begin(); listIter != buffList->end();listIter++) { free(listIter->argu1); free(listIter->argu2); free(listIter->argu3); } delete buffList; } delete bufMap; printf("Free Complete!\n"); sleep(10); printf("endend\n"); 

Thanks you.

When i use the top terminal program at linux, i can't see the result of free.

My expectation is

  1. free map and list.

  2. The memory usage that i can see at the top(linux function) or /proc/meminfo get smaller than past.

  3. sleep is start.

  4. program exit.

But The usage of memory only get smaller when the program is end.

Would you explain the logic of free function?

Below is my code.

for(mapIter = bufMap->begin(); mapIter != bufMap -> end();mapIter++) { list<buff> *buffList = mapIter->second; list<buff>::iterator listIter; for(listIter = buffList->begin(); listIter != buffList->end();listIter++) { free(listIter->argu1); free(listIter->argu2); free(listIter->argu3); } delete buffList; } delete bufMap; printf("Free Complete!\n"); sleep(10); printf("endend\n"); 

Thanks you.

When I use the top terminal program at Linux, I can't see the result of free.

My expectation is:

  1. free map and list.

  2. The memory usage that I can see at the top(Linux function) or /proc/meminfo get smaller than past.

  3. sleep is start.

  4. program exit.

But The usage of memory only gets smaller when the program ends.

Would you explain the logic of free function?

Below is my code.

for(mapIter = bufMap->begin(); mapIter != bufMap -> end();mapIter++) { list<buff> *buffList = mapIter->second; list<buff>::iterator listIter; for(listIter = buffList->begin(); listIter != buffList->end();listIter++) { free(listIter->argu1); free(listIter->argu2); free(listIter->argu3); } delete buffList; } delete bufMap; printf("Free Complete!\n"); sleep(10); printf("endend\n"); 

Thanks you.

Source Link

What is the free function logic?

When i use the top terminal program at linux, i can't see the result of free.

My expectation is

  1. free map and list.

  2. The memory usage that i can see at the top(linux function) or /proc/meminfo get smaller than past.

  3. sleep is start.

  4. program exit.

But The usage of memory only get smaller when the program is end.

Would you explain the logic of free function?

Below is my code.

for(mapIter = bufMap->begin(); mapIter != bufMap -> end();mapIter++) { list<buff> *buffList = mapIter->second; list<buff>::iterator listIter; for(listIter = buffList->begin(); listIter != buffList->end();listIter++) { free(listIter->argu1); free(listIter->argu2); free(listIter->argu3); } delete buffList; } delete bufMap; printf("Free Complete!\n"); sleep(10); printf("endend\n"); 

Thanks you.