improve image lifecycle handling

This commit is contained in:
Fabian Freund
2026-02-08 17:37:21 +01:00
parent 6f3a84fb31
commit d1e769fb7c
14 changed files with 126 additions and 51 deletions
@@ -331,6 +331,11 @@ class TabStates extends _$TabStates {
);
ref.onDispose(() async {
// Dispose all remaining tab images
for (final tab in state.values) {
_disposeTabImages(tab);
}
// Cancel all stream subscriptions
for (final sub in subscriptions) {
await sub.cancel();
@@ -41,7 +41,7 @@ final class TabStatesProvider
}
}
String _$tabStatesHash() => r'2d18c0c2105ce53bd13e6a6dff1d33c1b531919d';
String _$tabStatesHash() => r'985d2eb87c59c3a113b8bbcf9d96267c42a2f543';
abstract class _$TabStates extends $Notifier<Map<String, TabState>> {
Map<String, TabState> build();
@@ -71,8 +71,8 @@ class WebExtensionsState extends _$WebExtensionsState {
} else {
if (state.containsKey(extensionId)) {
state = {...state}..remove(extensionId);
// Dispose the cached image when extension is removed
_imageCache.remove(extensionId)?.dispose();
// remove() triggers onEvict which handles disposal
_imageCache.remove(extensionId);
}
}
}
@@ -83,9 +83,7 @@ class WebExtensionsState extends _$WebExtensionsState {
final image = await tryDecodeImage(bytes);
if (image != null) {
// Dispose old image only after successfully creating new one
_imageCache.get(extensionId)?.dispose();
// set() will evict the old entry via onEvict callback, which handles disposal
_imageCache.set(extensionId, image);
if (state.containsKey(extensionId)) {
@@ -62,7 +62,7 @@ final class WebExtensionsStateProvider
}
String _$webExtensionsStateHash() =>
r'd74f739a2f33395c10e30a81c8031f2f2630e418';
r'28cd9c99bc167fa1a051eccf3d23917a417e54ea';
final class WebExtensionsStateFamily extends $Family
with