Raheel Gupta <raheel...@gmail.com> wrote: > Sir, is there any way to not allow malloc to hold memory ? I mean shouldnt > free(), be freeing the memory ?
free() frees memory in the heap, making it available to other malloc again. But it does not necessarily shrink the amount of memory used by the process as was already explained by multiple replies. The OS does not necessarily shrink the memory of the process, when calling free() because that may be reused when the process allocate again. Shrinking/growing has a cost. But does it really matter to you that it does not shrink anyway? Pages that are not used will be paged out if other processes need more memory and if the page are really unused, then they will remain paged-out (no swapping) which has probably no performance penalty. It will use more virtual memory but it does not matter (unless of course you run out of virtual memory). How much physical memory is actively being used is what matters. Not also that just because you freed plenty of memory does not mean the OS can always reclaim the pages from the process anyway in case your heap was fragmented with tiny blocks still allocated all scattered all over the heap. Worth reading: http://unix.stackexchange.com/questions/53447/does-free-unmap-the-memory-of-a-process http://ftp.gnu.org/old-gnu/Manuals/glibc-2.2.3/html_chapter/libc_3.html Quoting the above link: === BEGIN QUOTE === Occasionally, free can actually return memory to the operating system and make the process smaller. Usually, all it can do is allow a later call to malloc to reuse the space. In the meantime, the space remains in your program as part of a free-list used internally by malloc. === END QUOTE === Regards Dominique _______________________________________________ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users