Subject: bug#45200: Memory leaks: (garbage-collect) fails to reclaim memory

From: Stefan Monnier <[email-masked]>
Date: Sun, 24 Jan 2021 14:12:20 -0500

> I'm fine with Emacs possibly keeping a dozen of megabytes for personal
> use. The problem though is that the issue easily manifests itself in
> hundreds of megabytes, as can be seen with the testcase marked as "Message
> #11" in web-ui.

I don't think the exact number matters: you were willing to make use of
*any* amount of extra memory by delaying all GC until idle time.
The fact that the GC you finally do after that long wait doesn't recover
that memory is not a failure in my book: there's no reason Emacs or
glibc should presume that you won't be reusing just as much heap space
before the next GC.

IOW in my book, you got what you asked for ;-)

BTW, I wish `malloc_trim` could be passed an argument that says
something like "release about half of the free memory", which would
provide a better balance between "hoard free memory indefinitely" and
"constantly free&reallocate memory from the OS".

Also, the manpage of mallopt suggests that glibc should automatically
do the trim on its own every once in a while anyway, so maybe the
problem won't be solved by `malloc_trim`.

        Stefan