Returning dynamically allocated memory back to OS without terminating the program
I am working on a program where I am using large but limited amount of memory. Memory is allocated and freed on run time on different threads. However, I noticed that the memory usage of the program would not remain within specified bounds. It would increase as time passed on. I wrote the following sample program to check whether memory is being freed back to the OS. Half the allocated memory was freed to check if the memory usage went down. int main() { char *p[COUNT]; for(int i = 0; i < COUNT; i++) { p[i] = new char[1048576]; memset (p[i], 0, 1048576); printf("%p\n", p[i]); } printf("done