madvise() MADV_DONTNEED allows this - http://man7.org/linux/man-pages/man2/madvise.2.html
It's also a flag in posix_madvise(), so the concept is reasonably portable.
It's also a flag in posix_madvise(), so the concept is reasonably portable.
Also, MADV_DONTNEED is only usable in some specific situations, like caches. I don't see how it could be used to implement things like "on low memory, trigger garbage collection and trim the heap to the smallest possible with munmap()".
So I thought you'd be interested to know that you can do just this with the standard functions mmap() and madvise().
No, it's not a replacement for malloc/free, but it does have value to some applications for some use cases.