Merge pull request #3150 from fufesou/fix/memory_issue_when_decode_slow_on_flutter
try fix memory issue when decoding is too slow
This commit is contained in:
commit
2a38f6bb16
@ -415,6 +415,8 @@ class ImageModel with ChangeNotifier {
|
||||
|
||||
String id = '';
|
||||
|
||||
int decodeCount = 0;
|
||||
|
||||
WeakReference<FFI> parent;
|
||||
|
||||
final List<Function(String)> _callbacksOnFirstImage = [];
|
||||
@ -434,12 +436,19 @@ class ImageModel with ChangeNotifier {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (decodeCount >= 1) {
|
||||
return;
|
||||
}
|
||||
|
||||
final pid = parent.target?.id;
|
||||
decodeCount += 1;
|
||||
ui.decodeImageFromPixels(
|
||||
rgba,
|
||||
parent.target?.ffiModel.display.width ?? 0,
|
||||
parent.target?.ffiModel.display.height ?? 0,
|
||||
isWeb ? ui.PixelFormat.rgba8888 : ui.PixelFormat.bgra8888, (image) {
|
||||
decodeCount -= 1;
|
||||
if (parent.target?.id != pid) return;
|
||||
try {
|
||||
// my throw exception, because the listener maybe already dispose
|
||||
|
Loading…
x
Reference in New Issue
Block a user