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

The memory was not cleared in a timely manner #384

Open
MQTwist opened this issue Dec 2, 2024 · 1 comment
Open

The memory was not cleared in a timely manner #384

MQTwist opened this issue Dec 2, 2024 · 1 comment

Comments

@MQTwist
Copy link

MQTwist commented Dec 2, 2024

Code

import 'package:flame_lottie/flame_lottie.dart';
import 'package:flutter/material.dart';
import 'package:flutter_application_1/page/widgets/ui/vendor_ui/manager/lottie_cache_manager.dart';
import 'package:get/get.dart';

class LottiePage extends StatefulWidget {
  const LottiePage({super.key});

  @override
  State<LottiePage> createState() => _LottiePageState();
}

class _LottiePageState extends State<LottiePage> {
  List<String> lotties = [
    "assets/lottie/home_top_1/data.json",
    "assets/lottie/home_top_2/data.json",
    "assets/lottie/home_top_3/data.json",
    "assets/lottie/home_top_banner_billon/data.json",
    "assets/lottie/home_top_banner_room/data.json",
    "assets/lottie/home_top_banner_stars/data.json",
  ];

  @override
  void initState() {
    super.initState();
  }

  @override
  void dispose() {
    Lottie.cache.clear();
    LottieCacheManager.instance.clear();
    super.dispose();
    debugPrint(">>>LottiePage dispose");
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(Get.arguments),
        actions: [
          IconButton(
              onPressed: () {
                Get.toNamed("EmptyPage");
              },
              icon: const Icon(Icons.abc))
        ],
      ),
      body: _body(),
    );
  }

  Widget _body() {
    return SizedBox.expand(
      child: ListView.builder(
        itemBuilder: _item,
        itemCount: 100,
        itemExtent: 100,
      ),
    );
  }

  Widget _item(BuildContext context, int index) {
    String lottie = lotties[index % lotties.length];
    return Lottie.asset(lottie);
  }
}

I called the method of clearing memory when dispose

Lottie.cache.clear();
LottieCacheManager.instance.clear();

Below are screenshots of memory during push and pop operations

Before push

QQ_1733120811986

Push and show animation

QQ_1733120883519

Pop page and clear

QQ_1733120936501

Flutter doctor output

[✓] Flutter (Channel stable, 3.22.2, on macOS 13.4 22F66 darwin-x64, locale zh-Hans-CN)
[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
[!] Xcode - develop for iOS and macOS (Xcode 14.3.1)
    ! Flutter recommends a minimum Xcode version of 15.
      Download the latest version or update via the Mac App Store.
[✓] Chrome - develop for the web
[✓] Android Studio (version 2022.2)
[✓] VS Code (version 1.95.3)
[✓] Connected device (4 available)
[✓] Network resources

lottie version 3.1.3,Device is iPhone 8, system version 16.2

@ritick-plateron
Copy link

Same issue here, Tried to find a workaround, But no luck... Any further updates?

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

2 participants