Subject: Re: bug#56546: 29.0.50; unbounded RAM comsumption when displaying images

From: "Jose A. Ortega Ruiz" <[email-masked]>
Date: Thu, 14 Jul 2022 13:23:01 +0100

On Thu, Jul 14 2022, Eli Zaretskii wrote:

>> From: "Jose A. Ortega Ruiz" <[email-masked]>
>> Date: Thu, 14 Jul 2022 02:35:46 +0100
>> 
>> 
>> It seems to be easy to make emacs (under X) to consume more and more
>> RAM, which is never released, by making it display images.  A extreme
>> (in my experience) case is animated GIFs, try:
>> 
>>   - emacs -Q
>>   - M-x eww RET https://xenodium.com/emacs-zones-to-lift-you-up/
>>   - RAM consumption grows to ~600Mb
>>   - R (redisplay page): RAM grows to ~1100Mb
>>   - R (redisplay page): RAM grows to ~1752Mb
>>   - R (redisplay page): RAM grows to ~2222Mb
>>   - rinse and repeat: RAM never goes down
>>   - (image-cache-size) reports a modest 82Mb
>>   - Kill buffer:  high RAM consumption is still at its maximum, even
>>     after (image-cache-size) goes to 0
>
> Run some utility that displays the memory-map of an application, and
> you will see that most of that memory is free for use.  Emacs just
> didn't release it to the OS, but kept it in the memory pages allocated
> to the process, for future allocations.

then, why is the process not reusing that memory the second, third,
etc. times i reload the exact same page, with the exact same images in
the same buffer? if the first allocation reserved that memory and the
process has it, after killing the buffer and opening the page again, it
has plenty of free for use memory at its disposal, yet it allocates a
fresh new block of 600Mb every time.  with that behaviour, i just have
to open 10 times the same page to run out of RAM in my computer.  not
even firefox is that hungry.

> The strategy for releasing memory to the OS is in glibc, not under our
> control.  Last time we talked with glibc developers, they maintained
> that this is the expected and correct behavior.

well, all i can say is that none of the programs i use in my linux
distribution (debian unstable), which are compiled against the same
libraries, has shown such a dramatic increase of RAM consumption in the
last months.  so they seem to have optimized their allocation behaviour
very narrowly against the way i use emacs! ;)

perhaps i'll try to compile emacs using older gcc versions (up to version
27, emacs was really slim RAM-wise for me).

thanks,
jao