Skip to content

Conversation

@marcocondrache
Copy link
Contributor

@marcocondrache marcocondrache commented Jan 4, 2026

Closes #39914

I was able to reproduce the issue on macOS using the same README.

The root cause was that markdown_preview_view attaches the image cache to the root div, and while Div correctly applies that cache during request_layout and paint, the prepaint phase didn’t have the same context.

Markdown is rendered through a List, and List::prepaint renders its items using layout_as_root. That meant images were getting loaded during prepaint without the image cache in place. When that happened, Img fell back to the global asset loader, which retains assets indefinitely unless explicitly cleaned up.

So every image was loaded twice:

  • once during layout/paint via RetainAllImageCache (correctly released when the preview closed)
  • once during prepaint via the global asset system (never released)

The result was doubled memory usage and a leak, since the globally loaded images stuck around after the preview was closed.

Release Notes:

  • Fixed a memory leak when previewing markdown files with images
Signed-off-by: Marco Mihai Condrache <52580954+marcocondrache@users.noreply.github.com>
@cla-bot cla-bot bot added the cla-signed The user has signed the Contributor License Agreement label Jan 4, 2026
@github-actions github-actions bot added the community champion Issues filed by our amazing community champions! 🫶 label Jan 4, 2026
Copy link
Member

@Veykril Veykril left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@Veykril Veykril merged commit e57285f into zed-industries:main Jan 5, 2026
26 checks passed
rtfeldman pushed a commit that referenced this pull request Jan 5, 2026
Closes #39914

I was able to reproduce the issue on macOS using the same README.

The root cause was that `markdown_preview_view` attaches the image cache
to the root div, and while Div correctly applies that cache during
request_layout and paint, the prepaint phase didn’t have the same
context.

Markdown is rendered through a List, and `List::prepaint` renders its
items using `layout_as_root`. That meant images were getting loaded
during prepaint without the image cache in place. When that happened,
Img fell back to the global asset loader, which retains assets
indefinitely unless explicitly cleaned up.

So every image was loaded twice:

- once during layout/paint via RetainAllImageCache (correctly released
when the preview closed)
- once during prepaint via the global asset system (never released)

The result was doubled memory usage and a leak, since the globally
loaded images stuck around after the preview was closed.

Release Notes:

- Fixed a memory leak when previewing markdown files with images

Signed-off-by: Marco Mihai Condrache <52580954+marcocondrache@users.noreply.github.com>
LivioGama pushed a commit to LivioGama/zed that referenced this pull request Jan 20, 2026
Closes zed-industries#39914

I was able to reproduce the issue on macOS using the same README.

The root cause was that `markdown_preview_view` attaches the image cache
to the root div, and while Div correctly applies that cache during
request_layout and paint, the prepaint phase didn’t have the same
context.

Markdown is rendered through a List, and `List::prepaint` renders its
items using `layout_as_root`. That meant images were getting loaded
during prepaint without the image cache in place. When that happened,
Img fell back to the global asset loader, which retains assets
indefinitely unless explicitly cleaned up.

So every image was loaded twice:

- once during layout/paint via RetainAllImageCache (correctly released
when the preview closed)
- once during prepaint via the global asset system (never released)

The result was doubled memory usage and a leak, since the globally
loaded images stuck around after the preview was closed.

Release Notes:

- Fixed a memory leak when previewing markdown files with images

Signed-off-by: Marco Mihai Condrache <52580954+marcocondrache@users.noreply.github.com>
LivioGama pushed a commit to LivioGama/zed that referenced this pull request Jan 20, 2026
Closes zed-industries#39914

I was able to reproduce the issue on macOS using the same README.

The root cause was that `markdown_preview_view` attaches the image cache
to the root div, and while Div correctly applies that cache during
request_layout and paint, the prepaint phase didn’t have the same
context.

Markdown is rendered through a List, and `List::prepaint` renders its
items using `layout_as_root`. That meant images were getting loaded
during prepaint without the image cache in place. When that happened,
Img fell back to the global asset loader, which retains assets
indefinitely unless explicitly cleaned up.

So every image was loaded twice:

- once during layout/paint via RetainAllImageCache (correctly released
when the preview closed)
- once during prepaint via the global asset system (never released)

The result was doubled memory usage and a leak, since the globally
loaded images stuck around after the preview was closed.

Release Notes:

- Fixed a memory leak when previewing markdown files with images

Signed-off-by: Marco Mihai Condrache <52580954+marcocondrache@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla-signed The user has signed the Contributor License Agreement community champion Issues filed by our amazing community champions! 🫶

2 participants