Why do you have to call malloc_trim()?
According to the docs [1,2] it should be called automatically when the free space exceeds the default M_TRIM_THRESHOLD of 128 KiB.
Is it because of this bug [3] or for another reason?
[1] https://man7.org/linux/man-pages/man3/malloc_trim.3.html
[2] https://man7.org/linux/man-pages/man3/mallopt.3.html
[3] https://sourceware.org/bugzilla/show_bug.cgi?id=14827