# gpui: Prepaint Div children with image cache \(\#46039\) · gitcafe/zed

[View on GitCafe](https://git.cafe/gitcafe/zed/commit/e57285fe3971404c041f13c80db1ec97adb7b493)

Repository: [gitcafe/zed](https://git.cafe/gitcafe/zed)

Visibility: public

Requested revision: e57285fe3971404c041f13c80db1ec97adb7b493

Requested commit: e57285fe3971404c041f13c80db1ec97adb7b493

Commit: e57285fe3971404c041f13c80db1ec97adb7b493

Tree: 920ef87410286b975263f11e7de1e313558b8ae2

Author: Marco Mihai Condrache

Committer: GitHub

## Message

```
gpui: Prepaint Div children with image cache (#46039)

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>
```

## Parents

- [e8fbd5beafc98e79bf487c7be33d921f2eab294c](https://git.cafe/gitcafe/zed/commit/e8fbd5beafc98e79bf487c7be33d921f2eab294c?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zed/tree/e57285fe3971404c041f13c80db1ec97adb7b493?format=markdown)
