diff options
author | webbeef <me@webbeef.org> | 2025-05-10 21:01:49 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-05-11 04:01:49 +0000 |
commit | e702bde9bf67cadc9a09fabdf9bf5fd0683f9231 (patch) | |
tree | 4b9555682a7116490db2083472e2848e7f2b6187 | |
parent | 9c3069366eece6d20fd6ccf48daa9a08d6d64d84 (diff) | |
download | servo-e702bde9bf67cadc9a09fabdf9bf5fd0683f9231.tar.gz servo-e702bde9bf67cadc9a09fabdf9bf5fd0683f9231.zip |
Delete WR images when dropping the ImageCacheStore (#36956)
This deletes images from WR when dropping the ImageCacheStore for a
WebView.
Testing: Run `./mach run --enable-experimental-web-platform-features
unsplash.com` and then open `about:memory` in a new tab. On Linux we end
up with ~30MB of WR images. Then close the unsplash.com tab and measure
memory again, it will down to ~1.25MB
Fixes: https://github.com/servo/servo/issues/25927
Signed-off-by: webbeef <me@webbeef.org>
-rw-r--r-- | components/net/image_cache.rs | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/components/net/image_cache.rs b/components/net/image_cache.rs index e3d31b11736..46a2a4ea111 100644 --- a/components/net/image_cache.rs +++ b/components/net/image_cache.rs @@ -7,7 +7,7 @@ use std::collections::hash_map::Entry::{Occupied, Vacant}; use std::sync::{Arc, Mutex}; use std::{mem, thread}; -use compositing_traits::{CrossProcessCompositorApi, SerializableImageData}; +use compositing_traits::{CrossProcessCompositorApi, ImageUpdate, SerializableImageData}; use imsz::imsz_from_reader; use ipc_channel::ipc::IpcSharedMemory; use log::{debug, warn}; @@ -675,6 +675,20 @@ impl ImageCache for ImageCacheImpl { } } +impl Drop for ImageCacheStore { + fn drop(&mut self) { + let image_updates = self + .completed_loads + .values() + .filter_map(|load| match &load.image_response { + ImageResponse::Loaded(image, _) => image.id.map(ImageUpdate::DeleteImage), + _ => None, + }) + .collect(); + self.compositor_api.update_images(image_updates); + } +} + impl ImageCacheImpl { /// Require self.store.lock() before calling. fn add_listener_with_store(&self, store: &mut ImageCacheStore, listener: ImageResponder) { |