GNU bug report logs - #66221
29.1; Animated webp image leaks memory

Previous Next

Package: emacs;

Reported by: johanwclaesson <at> gmail.com

Date: Tue, 26 Sep 2023 23:20:02 UTC

Severity: normal

Found in version 29.1

To reply to this bug, email your comments to 66221 AT debbugs.gnu.org.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#66221; Package emacs. (Tue, 26 Sep 2023 23:20:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to johanwclaesson <at> gmail.com:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Tue, 26 Sep 2023 23:20:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Johan Claesson <johanwclaesson <at> bahnhof.se>
To: bug-gnu-emacs <at> gnu.org
Subject: 29.1; Animated webp image leaks memory
Date: Tue, 26 Sep 2023 22:31:31 +0200
[Message part 1 (text/plain, inline)]

Hi,

It seem to me that animating webp images is sometimes leaking
memory.  This memory is not returned when buffer is killed and not
by calling clear-image-cache either.

For example running the following with the attached example
nooshi.webp copied to ones home directory seem to increase memory
consumption for every call (the amount it increases varies).

(require 'cl-macs)
(require 'image)

(defun memory ()
  (cdr (assq 'vsize (process-attributes (emacs-pid)))))

(let ((before (memory)))
  (with-temp-buffer
    (cl-loop for file in (make-list 10 "~/nooshi.webp")
             do (let ((image (create-image file nil nil :width 150)))
                  (display-buffer (current-buffer))
                  (insert-image image)
                  (image-animate image nil t)))
    (sit-for 1))
  (clear-image-cache)
  (message "memory increased %s KB" (- (memory) before)))

Regards,
/Johan

[nooshi.webp (image/webp, attachment)]
[Message part 3 (text/plain, inline)]

In GNU Emacs 29.1 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.33,
 cairo version 1.16.0) of 2023-09-20 built on goblin
Repository revision: a9b28224af0f73d1fe0f422e9b318c5b91af889b
Repository branch: HEAD
Windowing system distributor 'The X.Org Foundation', version 11.0.12101003
System Description: Ubuntu 22.04.1 LTS

Configured using:
 'configure --with-x-toolkit=gtk3 --without-compress-install
 --with-modules --with-native-compilation=aot --with-xft
 PKG_CONFIG_PATH=/home/jcl/usr/lib/pkgconfig'

Configured features:
ACL CAIRO DBUS FREETYPE GIF GLIB GMP GNUTLS GPM GSETTINGS HARFBUZZ JPEG
JSON LCMS2 LIBOTF LIBSELINUX LIBSYSTEMD LIBXML2 M17N_FLT MODULES
NATIVE_COMP NOTIFY INOTIFY PDUMPER PNG RSVG SECCOMP SOUND THREADS TIFF
TOOLKIT_SCROLL_BARS TREE_SITTER WEBP X11 XDBE XIM XINPUT2 XPM GTK3 ZLIB

Important settings:
  value of $LC_MONETARY: en_GB.UTF-8
  value of $LC_NUMERIC: en_GB.UTF-8
  value of $LC_TIME: en_GB.UTF-8
  value of $LANG: en_US.UTF-8
  value of $XMODIFIERS: @im=none
  locale-coding-system: utf-8-unix

Major mode: Lisp Interaction

Minor modes in effect:
  tooltip-mode: t
  global-eldoc-mode: t
  eldoc-mode: t
  show-paren-mode: t
  electric-indent-mode: t
  mouse-wheel-mode: t
  tool-bar-mode: t
  menu-bar-mode: t
  file-name-shadow-mode: t
  global-font-lock-mode: t
  font-lock-mode: t
  blink-cursor-mode: t
  line-number-mode: t
  indent-tabs-mode: t
  transient-mark-mode: t
  auto-composition-mode: t
  auto-encryption-mode: t
  auto-compression-mode: t

Load-path shadows:
None found.

Features:
(shadow sort mail-extr emacsbug message mailcap yank-media puny dired
dired-loaddefs rfc822 mml mml-sec password-cache epa derived epg rfc6068
epg-config gnus-util text-property-search time-date mm-decode mm-bodies
mm-encode mail-parse rfc2231 mailabbrev gmm-utils mailheader cl-loaddefs
comp comp-cstr warnings icons subr-x rx cl-seq cl-macs gv cl-extra
help-mode bytecomp byte-compile cl-lib sendmail rfc2047 rfc2045
ietf-drums mm-util mail-prsvr mail-utils rmc iso-transl tooltip cconv
eldoc paren electric uniquify ediff-hook vc-hooks lisp-float-type
elisp-mode mwheel term/x-win x-win term/common-win x-dnd tool-bar dnd
fontset image regexp-opt fringe tabulated-list replace newcomment
text-mode lisp-mode prog-mode register page tab-bar menu-bar rfn-eshadow
isearch easymenu timer select scroll-bar mouse jit-lock font-lock syntax
font-core term/tty-colors frame minibuffer nadvice seq simple cl-generic
indonesian philippine cham georgian utf-8-lang misc-lang vietnamese
tibetan thai tai-viet lao korean japanese eucjp-ms cp51932 hebrew greek
romanian slovak czech european ethiopic indian cyrillic chinese
composite emoji-zwj charscript charprop case-table epa-hook
jka-cmpr-hook help abbrev obarray oclosure cl-preloaded button loaddefs
theme-loaddefs faces cus-face macroexp files window text-properties
overlay sha1 md5 base64 format env code-pages mule custom widget keymap
hashtable-print-readable backquote threads dbusbind inotify lcms2
dynamic-setting system-font-setting font-render-setting cairo
move-toolbar gtk x-toolkit xinput2 x multi-tty make-network-process
native-compile emacs)

Memory information:
((conses 16 77501 6007)
 (symbols 48 7284 0)
 (strings 32 19960 2670)
 (string-bytes 1 584026)
 (vectors 16 15627)
 (vector-slots 8 326875 14561)
 (floats 8 37 46)
 (intervals 56 226 0)
 (buffers 984 10))

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#66221; Package emacs. (Wed, 27 Sep 2023 18:35:02 GMT) Full text and rfc822 format available.

Message #8 received at 66221 <at> debbugs.gnu.org (full text, mbox):

From: Garjola Dindi <garjola <at> garjola.net>
To: 66221 <at> debbugs.gnu.org
Cc: Johan Claesson <johanwclaesson <at> bahnhof.se>, johanwclaesson <at> gmail.com
Subject: Re: bug#66221: 29.1; Animated webp image leaks memory
Date: Wed, 27 Sep 2023 19:47:43 +0200
I run this on GNU Emacs 30.0.50 (build 1, x86_64-pc-linux-gnu, GTK+
Version 3.24.37, cairo version 1.16.0) of 2023-09-23 (built from master)
with -Q option and got this message:

Stopping animation; animation possibly too big [10 times]
memory increased 167716 KB

So I guess this confirms the leak.



On Tue 26-Sep-2023 at 22:31:31 +02, Johan Claesson
<johanwclaesson <at> bahnhof.se> wrote: 
> Hi,
>
> It seem to me that animating webp images is sometimes leaking
> memory.  This memory is not returned when buffer is killed and not
> by calling clear-image-cache either.
>
> For example running the following with the attached example
> nooshi.webp copied to ones home directory seem to increase memory
> consumption for every call (the amount it increases varies).
>
> (require 'cl-macs)
> (require 'image)
>
> (defun memory ()
>   (cdr (assq 'vsize (process-attributes (emacs-pid)))))
>
> (let ((before (memory)))
>   (with-temp-buffer
>     (cl-loop for file in (make-list 10 "~/nooshi.webp")
>              do (let ((image (create-image file nil nil :width 150)))
>                   (display-buffer (current-buffer))
>                   (insert-image image)
>                   (image-animate image nil t)))
>     (sit-for 1))
>   (clear-image-cache)
>   (message "memory increased %s KB" (- (memory) before)))
>
> Regards,
> /Johan
>
>
>
>
> In GNU Emacs 29.1 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.33,
>  cairo version 1.16.0) of 2023-09-20 built on goblin
> Repository revision: a9b28224af0f73d1fe0f422e9b318c5b91af889b
> Repository branch: HEAD
> Windowing system distributor 'The X.Org Foundation', version 11.0.12101003
> System Description: Ubuntu 22.04.1 LTS
>
> Configured using:
>  'configure --with-x-toolkit=gtk3 --without-compress-install
>  --with-modules --with-native-compilation=aot --with-xft
>  PKG_CONFIG_PATH=/home/jcl/usr/lib/pkgconfig'
>
> Configured features:
> ACL CAIRO DBUS FREETYPE GIF GLIB GMP GNUTLS GPM GSETTINGS HARFBUZZ JPEG
> JSON LCMS2 LIBOTF LIBSELINUX LIBSYSTEMD LIBXML2 M17N_FLT MODULES
> NATIVE_COMP NOTIFY INOTIFY PDUMPER PNG RSVG SECCOMP SOUND THREADS TIFF
> TOOLKIT_SCROLL_BARS TREE_SITTER WEBP X11 XDBE XIM XINPUT2 XPM GTK3 ZLIB
>
> Important settings:
>   value of $LC_MONETARY: en_GB.UTF-8
>   value of $LC_NUMERIC: en_GB.UTF-8
>   value of $LC_TIME: en_GB.UTF-8
>   value of $LANG: en_US.UTF-8
>   value of $XMODIFIERS: @im=none
>   locale-coding-system: utf-8-unix
>
> Major mode: Lisp Interaction
>
> Minor modes in effect:
>   tooltip-mode: t
>   global-eldoc-mode: t
>   eldoc-mode: t
>   show-paren-mode: t
>   electric-indent-mode: t
>   mouse-wheel-mode: t
>   tool-bar-mode: t
>   menu-bar-mode: t
>   file-name-shadow-mode: t
>   global-font-lock-mode: t
>   font-lock-mode: t
>   blink-cursor-mode: t
>   line-number-mode: t
>   indent-tabs-mode: t
>   transient-mark-mode: t
>   auto-composition-mode: t
>   auto-encryption-mode: t
>   auto-compression-mode: t
>
> Load-path shadows:
> None found.
>
> Features:
> (shadow sort mail-extr emacsbug message mailcap yank-media puny dired
> dired-loaddefs rfc822 mml mml-sec password-cache epa derived epg rfc6068
> epg-config gnus-util text-property-search time-date mm-decode mm-bodies
> mm-encode mail-parse rfc2231 mailabbrev gmm-utils mailheader cl-loaddefs
> comp comp-cstr warnings icons subr-x rx cl-seq cl-macs gv cl-extra
> help-mode bytecomp byte-compile cl-lib sendmail rfc2047 rfc2045
> ietf-drums mm-util mail-prsvr mail-utils rmc iso-transl tooltip cconv
> eldoc paren electric uniquify ediff-hook vc-hooks lisp-float-type
> elisp-mode mwheel term/x-win x-win term/common-win x-dnd tool-bar dnd
> fontset image regexp-opt fringe tabulated-list replace newcomment
> text-mode lisp-mode prog-mode register page tab-bar menu-bar rfn-eshadow
> isearch easymenu timer select scroll-bar mouse jit-lock font-lock syntax
> font-core term/tty-colors frame minibuffer nadvice seq simple cl-generic
> indonesian philippine cham georgian utf-8-lang misc-lang vietnamese
> tibetan thai tai-viet lao korean japanese eucjp-ms cp51932 hebrew greek
> romanian slovak czech european ethiopic indian cyrillic chinese
> composite emoji-zwj charscript charprop case-table epa-hook
> jka-cmpr-hook help abbrev obarray oclosure cl-preloaded button loaddefs
> theme-loaddefs faces cus-face macroexp files window text-properties
> overlay sha1 md5 base64 format env code-pages mule custom widget keymap
> hashtable-print-readable backquote threads dbusbind inotify lcms2
> dynamic-setting system-font-setting font-render-setting cairo
> move-toolbar gtk x-toolkit xinput2 x multi-tty make-network-process
> native-compile emacs)
>
> Memory information:
> ((conses 16 77501 6007)
>  (symbols 48 7284 0)
>  (strings 32 19960 2670)
>  (string-bytes 1 584026)
>  (vectors 16 15627)
>  (vector-slots 8 326875 14561)
>  (floats 8 37 46)
>  (intervals 56 226 0)
>  (buffers 984 10))
-- 




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#66221; Package emacs. (Fri, 29 Sep 2023 13:34:01 GMT) Full text and rfc822 format available.

Message #11 received at 66221 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Garjola Dindi <garjola <at> garjola.net>
Cc: johanwclaesson <at> bahnhof.se, johanwclaesson <at> gmail.com, 66221 <at> debbugs.gnu.org
Subject: Re: bug#66221: 29.1; Animated webp image leaks memory
Date: Fri, 29 Sep 2023 16:32:59 +0300
> Cc: Johan Claesson <johanwclaesson <at> bahnhof.se>, johanwclaesson <at> gmail.com
> From: Garjola Dindi <garjola <at> garjola.net>
> Date: Wed, 27 Sep 2023 19:47:43 +0200
> 
> 
> I run this on GNU Emacs 30.0.50 (build 1, x86_64-pc-linux-gnu, GTK+
> Version 3.24.37, cairo version 1.16.0) of 2023-09-23 (built from master)
> with -Q option and got this message:
> 
> Stopping animation; animation possibly too big [10 times]
> memory increased 167716 KB
> 
> So I guess this confirms the leak.

I don't think there's a leak.  Emacs makes it hard to know when to
free the animation-related memory and which parts of it to remove,
because the low-level code which handles this memory doesn't have
anyway of knowing whether the animation will be reused.  See
bug#56546.  Maybe we have one more issue here.  Or maybe the memory
consumption is not due to the animation caches at all.  Or maybe if
you wait longer than image-cache-eviction-delay the memory does get
released.

Feel free to step through clear-image-cache and see what happens
there.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#66221; Package emacs. (Fri, 29 Sep 2023 15:44:02 GMT) Full text and rfc822 format available.

Message #14 received at 66221 <at> debbugs.gnu.org (full text, mbox):

From: Stefan Kangas <stefankangas <at> gmail.com>
To: Eli Zaretskii <eliz <at> gnu.org>, Garjola Dindi <garjola <at> garjola.net>
Cc: johanwclaesson <at> bahnhof.se, johanwclaesson <at> gmail.com, larsi <at> gnus.org,
 66221 <at> debbugs.gnu.org
Subject: Re: bug#66221: 29.1; Animated webp image leaks memory
Date: Fri, 29 Sep 2023 08:42:34 -0700
Eli Zaretskii <eliz <at> gnu.org> writes:

> Feel free to step through clear-image-cache and see what happens
> there.

I noticed that `clear-image-cache' won't clear the rest of the image
cache if we have a non-empty animation_cache.  Is that expected?

IOW, would a change like the following make more sense?

diff --git a/src/image.c b/src/image.c
index 84db9bfb3b8..e98768e70bd 100644
--- a/src/image.c
+++ b/src/image.c
@@ -2345,7 +2345,6 @@ DEFUN ("clear-image-cache", Fclear_image_cache,
Sclear_image_cache,
 #if defined (HAVE_WEBP) || defined (HAVE_GIF)
       anim_prune_animation_cache (XCDR (animation_cache));
 #endif
-      return Qnil;
     }

   if (! (NILP (filter) || FRAMEP (filter)))




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#66221; Package emacs. (Fri, 29 Sep 2023 16:25:01 GMT) Full text and rfc822 format available.

Message #17 received at 66221 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Stefan Kangas <stefankangas <at> gmail.com>
Cc: garjola <at> garjola.net, johanwclaesson <at> bahnhof.se, johanwclaesson <at> gmail.com,
 larsi <at> gnus.org, 66221 <at> debbugs.gnu.org
Subject: Re: bug#66221: 29.1; Animated webp image leaks memory
Date: Fri, 29 Sep 2023 19:23:21 +0300
> From: Stefan Kangas <stefankangas <at> gmail.com>
> Date: Fri, 29 Sep 2023 08:42:34 -0700
> Cc: johanwclaesson <at> bahnhof.se, johanwclaesson <at> gmail.com, 66221 <at> debbugs.gnu.org, 
> 	larsi <at> gnus.org
> 
> Eli Zaretskii <eliz <at> gnu.org> writes:
> 
> > Feel free to step through clear-image-cache and see what happens
> > there.
> 
> I noticed that `clear-image-cache' won't clear the rest of the image
> cache if we have a non-empty animation_cache.  Is that expected?
> 
> IOW, would a change like the following make more sense?

I don't know, sorry.  Maybe Lars can answer that.





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#66221; Package emacs. (Fri, 29 Sep 2023 23:20:01 GMT) Full text and rfc822 format available.

Message #20 received at 66221 <at> debbugs.gnu.org (full text, mbox):

From: Alan Third <alan <at> idiocy.org>
To: Stefan Kangas <stefankangas <at> gmail.com>
Cc: Garjola Dindi <garjola <at> garjola.net>, 66221 <at> debbugs.gnu.org,
 johanwclaesson <at> bahnhof.se, johanwclaesson <at> gmail.com, larsi <at> gnus.org,
 Eli Zaretskii <eliz <at> gnu.org>
Subject: Re: bug#66221: 29.1; Animated webp image leaks memory
Date: Sat, 30 Sep 2023 00:19:17 +0100
On Fri, Sep 29, 2023 at 08:42:34AM -0700, Stefan Kangas wrote:
> Eli Zaretskii <eliz <at> gnu.org> writes:
> 
> > Feel free to step through clear-image-cache and see what happens
> > there.
> 
> I noticed that `clear-image-cache' won't clear the rest of the image
> cache if we have a non-empty animation_cache.  Is that expected?

"animation_cache" in this context is an image spec to be removed from
the animation cache, not the animation cache itself.

It caught me out too when I was looking at this code the other day.

-- 
Alan Third




This bug report was last modified 217 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.