Skip to content

Memory leak when using inline image feature

Memory Usage

  • iTerm2 version: Build 3.5.0beta5
  • OS version: macOS Monterey (12.3.1)

Detailed steps to reproduce the problem

  1. Output a lot of hi-res images as described by https://iterm2.com/documentation-images.html (I mean like thousands)
  2. Clear your scrollback, Reset, or even close the session where you did it
  3. See how ITerm allocated a lot of memory.

What happened

iTerm2 allocates space for the images but seems to never free it again.

This is part of vmmap after listing only some hundred images inline:

CG image                          10.2G    10.2G    10.2G       0K       0K       0K       0K     1110
...
VM_ALLOCATE                        9.5G     9.5G     9.5G       0K       0K       0K       0K      956
...
===========                     ======= ========    =====  ======= ========   ======    =====  =======
TOTAL                             25.4G    21.8G    20.9G     232K    37.3M    51.4M       0K     7600
TOTAL, minus reserved VM space    25.4G    21.8G    20.9G     232K    37.3M    51.4M       0K     7600

I was notified by the system because iTerm2 used 300 GB while I was working on my terminal-based picture catalog system (written with Go) for some hours. As I checked with a fresh iTerm I found that memory is increasing and does not go back when clearing the scrollback or even closing the tab where I used the image output. It seems to leak those graphics.

The code I am using is currently not published but for the image output it basically just does the same as imgcat is doing.

What should have happened

iTerm2 should free memory for the images eventually.