mirror of
https://github.com/servo/servo.git
synced 2025-06-06 16:45:39 +00:00
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>
This commit is contained in:
parent
9c3069366e
commit
e702bde9bf
1 changed files with 15 additions and 1 deletions
|
@ -7,7 +7,7 @@ use std::collections::hash_map::Entry::{Occupied, Vacant};
|
||||||
use std::sync::{Arc, Mutex};
|
use std::sync::{Arc, Mutex};
|
||||||
use std::{mem, thread};
|
use std::{mem, thread};
|
||||||
|
|
||||||
use compositing_traits::{CrossProcessCompositorApi, SerializableImageData};
|
use compositing_traits::{CrossProcessCompositorApi, ImageUpdate, SerializableImageData};
|
||||||
use imsz::imsz_from_reader;
|
use imsz::imsz_from_reader;
|
||||||
use ipc_channel::ipc::IpcSharedMemory;
|
use ipc_channel::ipc::IpcSharedMemory;
|
||||||
use log::{debug, warn};
|
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 {
|
impl ImageCacheImpl {
|
||||||
/// Require self.store.lock() before calling.
|
/// Require self.store.lock() before calling.
|
||||||
fn add_listener_with_store(&self, store: &mut ImageCacheStore, listener: ImageResponder) {
|
fn add_listener_with_store(&self, store: &mut ImageCacheStore, listener: ImageResponder) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue