Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memory leak and crash with gapless #26

Open
fryette opened this issue Oct 24, 2022 · 2 comments
Open

Memory leak and crash with gapless #26

fryette opened this issue Oct 24, 2022 · 2 comments

Comments

@fryette
Copy link

fryette commented Oct 24, 2022

I got an issue with OOM on a very low device with random crashes. After investigation, I figure out that the problem with ImageHandler was reassigned.

Why did it happen?
Because in _OctoImageState in didUpdateWidget method each time reassign previous handler and saves current as well because of placeholder + progressBuilder properties. So in time, you have a situation where during the build method code executes build for all prev handlers and request all the images in the hierarchy(for 12 images on screen after 1 min with 10-sec delay of changing URL have 60 sec/10 delay =6 requests for each image + decoding job which cause the crash).

Fix proposal
Instead of each time reassigning handler need to create a new handler for the previous state without a placeholder and progress from the current handle or provide a way how to clear prev handler

instead of
_previousHandler = _imageHandler;
Need to recreate ImageHandler without placeholder from current ImageHandler

_previousHandler = ImageHandler(
          image: oldWidget.image,
          imageBuilder: oldWidget.imageBuilder,
          placeholderBuilder: oldWidget.placeholderBuilder,
          progressIndicatorBuilder: oldWidget.progressIndicatorBuilder,
          errorBuilder: oldWidget.errorBuilder,
          placeholderFadeInDuration: oldWidget.placeholderFadeInDuration,
          fadeOutDuration: oldWidget.fadeOutDuration,
          fadeOutCurve: oldWidget.fadeOutCurve,
          fadeInDuration: oldWidget.fadeInDuration,
          fadeInCurve: oldWidget.fadeInCurve,
          fit: oldWidget.fit,
          width: oldWidget.width,
          height: oldWidget.height,
          alignment: oldWidget.alignment,
          repeat: oldWidget.repeat,
          color: oldWidget.color,
          colorBlendMode: oldWidget.colorBlendMode,
          matchTextDirection: oldWidget.matchTextDirection,
          filterQuality: oldWidget.filterQuality,
        );

This issue is not related to Flutter 3.x. It's reproducible on 2.10.3 and 3.x.

I also saw a couple of old issues with CachableImage on flutter GitHub, and I think that can be a root cause of crashes

@fryette fryette changed the title Memory leak with gapless Memory leak and crash with gapless Oct 24, 2022
@bugrevealingbme
Copy link

I have the annoying problem too. I am using iPhone 13 Pro.

@momoDragon
Copy link

Facing a similar issue, app just crashes when loading a few large images in grid view
could not find any crash logs on xcode, firebase crashalytics, and user local device app crash logs in user diagnostics
device: iphone 13 pro ios16.1.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants