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:
parent
d732a7d361
commit
4758173c33
12 changed files with 181 additions and 46 deletions
|
@ -1,9 +1,9 @@
|
|||
use futures::FutureExt;
|
||||
use gpui::{
|
||||
App, AppContext, Application, Asset as _, AssetLogger, Bounds, ClickEvent, Context, ElementId,
|
||||
Entity, HashMapImageCache, ImageAssetLoader, ImageCache, ImageCacheProvider, KeyBinding, Menu,
|
||||
MenuItem, SharedString, TitlebarOptions, Window, WindowBounds, WindowOptions, actions, div,
|
||||
hash, image_cache, img, prelude::*, px, rgb, size,
|
||||
Entity, ImageAssetLoader, ImageCache, ImageCacheProvider, KeyBinding, Menu, MenuItem,
|
||||
RetainAllImageCache, SharedString, TitlebarOptions, Window, WindowBounds, WindowOptions,
|
||||
actions, div, hash, image_cache, img, prelude::*, px, rgb, size,
|
||||
};
|
||||
use reqwest_client::ReqwestClient;
|
||||
use std::{collections::HashMap, sync::Arc};
|
||||
|
@ -14,7 +14,7 @@ struct ImageGallery {
|
|||
image_key: String,
|
||||
items_count: usize,
|
||||
total_count: usize,
|
||||
image_cache: Entity<HashMapImageCache>,
|
||||
image_cache: Entity<RetainAllImageCache>,
|
||||
}
|
||||
|
||||
impl ImageGallery {
|
||||
|
@ -44,8 +44,8 @@ impl Render for ImageGallery {
|
|||
.text_color(gpui::white())
|
||||
.child("Manually managed image cache:")
|
||||
.child(
|
||||
image_cache(self.image_cache.clone()).child(
|
||||
div()
|
||||
.image_cache(self.image_cache.clone())
|
||||
.id("main")
|
||||
.font_family(".SystemUIFont")
|
||||
.text_color(gpui::black())
|
||||
|
@ -95,7 +95,7 @@ impl Render for ImageGallery {
|
|||
.map(|ix| img(format!("{}-{}", image_url, ix)).size_20()),
|
||||
),
|
||||
),
|
||||
))
|
||||
)
|
||||
.child(
|
||||
"Automatically managed image cache:"
|
||||
)
|
||||
|
@ -282,7 +282,7 @@ fn main() {
|
|||
image_key: "".into(),
|
||||
items_count: IMAGES_IN_GALLERY,
|
||||
total_count: 0,
|
||||
image_cache: HashMapImageCache::new(ctx),
|
||||
image_cache: RetainAllImageCache::new(ctx),
|
||||
})
|
||||
})
|
||||
.unwrap();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue