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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memory leak on real device only #938

Open
1 of 2 tasks
EArminjon opened this issue Apr 10, 2024 · 0 comments
Open
1 of 2 tasks

Memory leak on real device only #938

EArminjon opened this issue Apr 10, 2024 · 0 comments

Comments

@EArminjon
Copy link

EArminjon commented Apr 10, 2024

馃悰 Bug Report

On real device Android & iOS this package have a memory leak.

Our app got some crash in production because of this issue : we have a long list of product inside a paginated infinite list. User can scroll on it and some of them reported crash. After investigation we discover this memory leak.

Expected behavior

Constant RSS usage

Reproduction steps

Use code bellow and check on devtools the memory usage graph.

With CachedNetworkImage : (increase during scroll)
Capture d鈥檈虂cran 2024-04-10 a虁 17 01 45

With Image.network: (stable during scroll)
Capture d鈥檈虂cran 2024-04-10 a虁 17 02 46

import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/material.dart';

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

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
        useMaterial3: false,
      ),
      home: const Home(),
    );
  }
}

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

  @override
  State<Home> createState() => _HomeState();
}

class _HomeState extends State<Home> {
  bool useCachedNetwork = true;

  @override
  Widget build(BuildContext context) {
    return Builder(
      builder: (BuildContext context) {
        return Scaffold(
          appBar: AppBar(
            title: const Text("Memory leak"),
          ),
          floatingActionButton: FloatingActionButton.extended(
            label: Text(
              "Use ${useCachedNetwork ? "Image.network" : "CachedNetworkImage"}",
            ),
            onPressed: () {
              setState(() => useCachedNetwork = !useCachedNetwork);
            },
          ),
          body: ListView.builder(
            itemBuilder: (BuildContext context, int index) => SizedBox(
              height: 80,
              child: Card(
                child: Padding(
                  padding: const EdgeInsets.all(16),
                  child: Row(
                    children: <Widget>[
                      AspectRatio(
                        aspectRatio: 1,
                        child: useCachedNetwork
                            ? CachedNetworkImage(
                                imageUrl: "https://picsum.photos/id/$index/1000/1000",
                                errorListener: (_) {},
                                progressIndicatorBuilder: (
                                  BuildContext context,
                                  String url,
                                  DownloadProgress progress,
                                ) =>
                                    Center(
                                  child: CircularProgressIndicator(
                                    value: progress.progress,
                                  ),
                                ),
                                errorWidget: (_, __, ___) => const Center(
                                  child: Icon(Icons.error),
                                ),
                              )
                            : Image.network(
                                "https://picsum.photos/id/$index/1000/1000",
                                errorBuilder: (_, __, ___) => const Center(
                                  child: Icon(Icons.error),
                                ),
                              ),
                      ),
                      const SizedBox(width: 16),
                      Expanded(
                        child: Text(
                          index.toString(),
                        ),
                      ),
                    ],
                  ),
                ),
              ),
            ),
          ),
        );
      },
    );
  }
}

Configuration

Versions:

flutter: 3.16.8
cached_network_image: 3.3.1

Platform:

  • 馃摫 iOS
  • 馃 Android (Pixel 7 Android 14)
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

1 participant