Closed alex-melnyk closed 3 weeks ago
Hi @alex-melnyk when is the next release with this fix planned?
Hi @alex-melnyk when is the next release with this fix planned?
I'm not responsible for the release of this package. Also, I would close this issue since the root of the issue isn't there.
Hi @alex-melnyk what was the root cause? I've experienced battery drain on my Android test device.
Hi @alex-melnyk what was the root cause? I've experienced battery drain on my Android test device.
Well... to get image file resolution I've been used Image
class to load the image file and get its size:
/// Returns a [Size] of the [imageFile].
static Future<Size> getImageSize(File imageFile) async {
final completer = Completer<Size>();
final imageStream = Image.file(imageFile).image.resolve(
ImageConfiguration.empty,
);
late final ImageStreamListener listener;
listener = ImageStreamListener(
(image, __) {
// Remove the listener to avoid potential memory leak
imageStream.removeListener(listener);
completer.complete(
Size(
image.image.width.toDouble(),
image.image.height.toDouble(),
),
);
},
onError: (exception, stackTrace) {
// Remove the listener on error
imageStream.removeListener(listener);
completer.completeError(exception, stackTrace);
},
);
imageStream.addListener(listener);
return completer.future;
}
For my case issue was related to missed lines to remove the listener, in that case platform won't release the stream and each time it propagates more and more freezes streams that allocate memory but never release it.
imageStream.removeListener(listener);
Version
2.1.0
Platforms
iOS
Device Model
all iOS devices
flutter info
How to reproduce?
Run an example code for 30 files at once in the loop and repeat that operation 4-5 times.
In the profile mode you can observe that memory allocated but never release.
Logs
Example code (optional)
Contact
@alex-melnyk