I have a long-living application with frequent memory allocation-deallocation. Will any malloc
implementation return freed memory back to the system?
What is, in this respect, the behavior of:
- ptmalloc 1, 2 (glibc default) or 3
- dlmalloc
- tcmalloc (google threaded malloc)
- solaris 10-11 default malloc and mtmalloc
- FreeBSD 8 default malloc (jemalloc)
- Hoard malloc?
Update
If I have an application whose memory consumption can be very different in daytime and nighttime (e.g.), can I force any of malloc
's to return freed memory to the system?
Without such return freed memory will be swapped out and in many times, but such memory contains only garbage.
malloc
andfree
functions only allocate address space in the process. And there's no point in returning that to the operating system -- that doesn't even really mean anything. And physical memory can be reclaimed by the operating system without it having to be given back. – TabularMADV_DONTNEED
has no effect on fragmentation. – Tabular