It looks like by default, the GNU libc won't return pages to the OS until 128 KiB are free at the top of the heap segment. The compiler has to make many small allocations, so even if it freed memory at every opportunity I doubt the heap trimming would happen very often.
Source: https://code.woboq.org/userspace/glibc/malloc/malloc.c.html#...