dispose images correctly
This commit is contained in:
@@ -20,10 +20,28 @@
|
||||
import 'dart:ui';
|
||||
|
||||
class EquatableImage {
|
||||
final Image value;
|
||||
Image? _value;
|
||||
final int _imageHash;
|
||||
bool _isDisposed = false;
|
||||
|
||||
EquatableImage(this.value, {required int hash}) : _imageHash = hash;
|
||||
EquatableImage(Image value, {required int hash})
|
||||
: _value = value,
|
||||
_imageHash = hash;
|
||||
|
||||
/// The underlying ui.Image. Returns null if disposed.
|
||||
Image? get value => _isDisposed ? null : _value;
|
||||
|
||||
/// Whether this image has been disposed.
|
||||
bool get isDisposed => _isDisposed;
|
||||
|
||||
/// Disposes the underlying ui.Image to free GPU memory.
|
||||
/// This is safe to call multiple times.
|
||||
void dispose() {
|
||||
if (_isDisposed) return;
|
||||
_isDisposed = true;
|
||||
_value?.dispose();
|
||||
_value = null;
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode => _imageHash.hashCode;
|
||||
|
||||
@@ -86,11 +86,14 @@ class GenericWebsiteService extends _$GenericWebsiteService {
|
||||
//Global icon cache
|
||||
late CacheRepository _cacheRepository;
|
||||
//Local decoded icon cache
|
||||
final LRUCache<String, BrowserIcon> _browserIconCache;
|
||||
late final LRUCache<String, BrowserIcon> _browserIconCache;
|
||||
|
||||
GenericWebsiteService()
|
||||
: _iconsService = GeckoIconService(),
|
||||
_browserIconCache = LRUCache(50);
|
||||
_browserIconCache = LRUCache(
|
||||
50,
|
||||
onEvict: (icon) => icon.image.dispose(),
|
||||
);
|
||||
|
||||
@override
|
||||
void build() {
|
||||
|
||||
@@ -42,7 +42,7 @@ final class GenericWebsiteServiceProvider
|
||||
}
|
||||
|
||||
String _$genericWebsiteServiceHash() =>
|
||||
r'44d6e4cc161b1200070d99e29c1db04cd18ca091';
|
||||
r'32a561820bda432f3c17e05b9da9c85871efffb4';
|
||||
|
||||
abstract class _$GenericWebsiteService extends $Notifier<void> {
|
||||
void build();
|
||||
|
||||
Reference in New Issue
Block a user