Skip to content

Conversation

@mertalev
Copy link
Member

@mertalev mertalev commented Sep 3, 2025

Description

The app continues to load images when it's inactive but not yet paused. This can lead to errors and makes it a more likely candidate to be harvested by the OS due to higher memory usage. This PR handles this by pausing image requests and resuming them when the app is active again.

Comment on lines 193 to 205
void _cancelImageStream() {
final imageProvider = widget.imageProvider;
if (imageProvider is CancellableImageProvider) {
imageProvider.cancel();
}
_stopListeningToImageStream();
}

void _cancelThumbhashStream() {
final thumbhashProvider = widget.thumbhashProvider;
if (thumbhashProvider is CancellableImageProvider) {
thumbhashProvider.cancel();
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do wonder if we need separate methods for the two providers like this? Both can be upcasted to ImageProvider, then dowcast them back to CancellableImageProvider and cancel it


@override
void didChangeAppLifecycleState(AppLifecycleState state) {
if (!mounted) return;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (!mounted) return;
if (!mounted) {
return;
}

@mertalev mertalev force-pushed the fix/mobile-gpu-error branch from eb70a45 to fda8058 Compare September 4, 2025 01:46
@mertalev mertalev changed the title fix(mobile): cancel image loading on inactive state fix(mobile): pause image loading on inactive state Sep 4, 2025
@alextran1502 alextran1502 merged commit e427778 into main Sep 4, 2025
51 checks passed
@alextran1502 alextran1502 deleted the fix/mobile-gpu-error branch September 4, 2025 13:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants