Skip to content

OOM crashes still possible for GIFs with a high number of required frames #24835

Closed

Description

@mklim

The limit added to cached decoded GIF frames in #20998 doesn't apply to required frames.

More info on required and dependent frames is covered in this article on caching decoding frames in Chromium.

Steps to Reproduce

  1. Find a large GIF with a high amount of required frames (example posted in this comment).
  2. Add it to the following app.
import 'package:flutter/material.dart';

void main() {
  runApp(MyApp());
}

class ThirdSlide extends StatefulWidget {
  @override
  _ThirdSlideState createState() => _ThirdSlideState();
}

class _ThirdSlideState extends State<ThirdSlide> {
  @override
  void initState() {
    PaintingBinding.instance.decodedCacheRatioCap = 1;
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      decoration: BoxDecoration(color: Theme.of(context).primaryColor),
      child: Column(mainAxisAlignment: MainAxisAlignment.center, children: [
        Expanded(
          child: Image(
            image: AssetImage("assets/test.gif"),
            fit: BoxFit.cover,
          ),
        ),
      ]),
    );
  }
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) => Container(child: ThirdSlide());
}
  1. flutter run on an iOS 10.3.3 device

Expected: GIF animates.
Actual: App crashes.

Logs

[   +8 ms] Result: {type: FlutterViewList, views: [{type: FlutterView, id: _flutterView/0x17d3b87c, isolate: {type: @Isolate, fixedId: true, id: isolates/611148326, name: main.dart$main.dart-611148326, number: 611148326}}]}
[        ] Connected to _flutterView/0x17d3b87c.
[   +1 ms] 🔥  To hot reload changes while running, press "r". To hot restart (and rebuild state), press "R".
[        ] An Observatory debugger and profiler is available at: http://127.0.0.1:1033/
[        ] For a more detailed help message, press "h". To detach, press "d"; to quit, press "q".
[+44623 ms] Service protocol connection closed.
[   +1 ms] Lost connection to device.
[        ] Sending to VM service: _deleteDevFS({fsName: tester})
[ +254 ms] TimeoutException after 0:00:00.250000: Future not completed
[   +4 ms] "flutter run" took 83,168ms.
Analyzing tester...
No issues found! (ran in 1.7s)
[✓] Flutter (Channel master, v0.11.8-pre.40, on Mac OS X 10.13.6 17G2112, locale en-US)
    • Flutter version 0.11.8-pre.40
    • Framework revision 9d878ca493 (17 hours ago), 2018-11-27 22:31:49 -0800
    • Engine revision be973ea196
    • Dart version 2.1.0 (build 2.1.0-dev.9.4 f9ebf21297)

Activity

  1. added
    c: crashStack traces logged to the console
    platform-iosiOS applications specifically
    engineflutter/engine related. See also e: labels.
    on Nov 29, 2018
  2. self-assigned this
    on Nov 29, 2018
  3. tsun424 commented on Nov 29, 2018

    @tsun424

    Hi @mklim , following the issue #20998 , the only doubt I have is I've tested the same gif file on several devices, including 2 iPads, iPad mini, iPhone and Android phone, the crash only happened on 1 iPad and iPad mini, for other iPad, iPhone and Android, no any crash observed.

  4. mklim commented on Nov 29, 2018

    @mklim
    ContributorAuthor

    @tsun424 double checked to make sure and I'm seeing the test GIF interpreted the same way across multiple different OS versions. Looks like there's always a linear climb in memory usage based on every frame being required until the GIF fully animates once (800MB) or the OS shuts the app down for using too much memory. It's hard to say for sure why we're only seeing actual crashes in that specific OS version, but my guess is that it happens to be more aggressive about shutting down the app for using memory like this than the other OS versions are. Or there's some strange coincidence where the 10.3.3 devices are all more memory constrained. I think larger GIFs with all required frames would probably go on to trigger crashes in other combinations of OS versions/devices too.

  5. tsun424 commented on Nov 29, 2018

    @tsun424

    Hi @mklim , make sense, appreciate your further checks. 👍

  6. eseidelGoogle commented on Nov 30, 2018

    @eseidelGoogle
    Contributor

    I wonder what Chrome's gif decoder/playback does. I know the person who used to maintain that code, but we'd have to do digging to find out the modern maintainer if that's helpful to you.

  7. mklim commented on Nov 30, 2018

    @mklim
    ContributorAuthor

    @eseidel Thanks! If I'm remembering right, they generally cache the previous frame to avoid repetitive decodes for cases of required frames like this, and then never try to cache non-required frames to avoid decoding again on loop. So they're using much less memory than us at the expense of CPU/battery. I think that makes sense in a lot of cases, but earlier when I was solving the original bug it sounded like we didn't want to unilaterally make the same tradeoff. Maybe we want to expose that kind of behavior as a lever or something going forward though? /cc @Hixie

  8. Hixie commented on Nov 30, 2018

    @Hixie
    Contributor

    Using 800MB for one GIF is clearly beyond reasonable, but I've no idea what the right heuristic is.

  9. added a commit that references this issue on Dec 22, 2018
    770536a
  10. github-actions commented on Aug 31, 2021

    @github-actions

    This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

  11. locked as resolved and limited conversation to collaborators on Aug 31, 2021
  12. added a commit that references this issue on Oct 9, 2026
    e620d90
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

c: crashStack traces logged to the consoleengineflutter/engine related. See also e: labels.platform-iosiOS applications specificallywaiting for PR to land (fixed)A fix is in flight

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions