gpui: Prepaint Div children with image cache (#46039)
Marco Mihai Condrache
created
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>