Use image cache to stop leaking images (#29452)

This PR fixes several possible memory leaks due to loading images in
markdown files and the image viewer, using the new image cache APIs

TODO: 
- [x] Ensure this didn't break rendering in any of the affected
components.

Release Notes:

- Fixed several image related memory leaks
This commit is contained in:
Mikayla Maki 2025-04-29 12:30:16 -07:00 committed by GitHub
parent d732a7d361
commit 4758173c33
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
12 changed files with 181 additions and 46 deletions

View file

@ -1537,6 +1537,22 @@ impl Image {
.and_then(|result| result.ok())
}
/// Use the GPUI `get_asset` API to make this image renderable
pub fn get_render_image(
self: Arc<Self>,
window: &mut Window,
cx: &mut App,
) -> Option<Arc<RenderImage>> {
ImageSource::Image(self)
.get_data(None, window, cx)
.and_then(|result| result.ok())
}
/// Use the GPUI `remove_asset` API to drop this image, if possible.
pub fn remove_asset(self: Arc<Self>, cx: &mut App) {
ImageSource::Image(self).remove_asset(cx);
}
/// Convert the clipboard image to an `ImageData` object.
pub fn to_image_data(&self, svg_renderer: SvgRenderer) -> Result<Arc<RenderImage>> {
fn frames_for_image(