Repository: flutter
Issue: Using `precacheImage` cause memory spike until crash
Labels: c: crash,e: device-specific,c: performance,a: images,perf: memory,P3,team-framework,triaged-framework

### Steps to reproduce

run sample code

### Expected results

Not crash

### Actual results

Memory increase until crash

### Code sample

<details open><summary>Code sample</summary>

```dart
void main() async{
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {

    return MaterialApp(
    title: 'Flutter Demo',
    localizationsDelegates: const [
      GlobalMaterialLocalizations.delegate,
      GlobalWidgetsLocalizations.delegate,
      GlobalCupertinoLocalizations.delegate,
//                RefreshLocalizations.delegate,
    ],
    theme: ThemeData(
      primarySwatch: Colors.blue,
    ),
    home: const MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key, required this.title});

  final String title;

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  int _counter = 0;

  late final Timer _timer;

  final _pageController = PageController();

  void _incrementCounter() {
    // setState(() {
    //   _counter++;
    // });
    _counter++;
    print('${_counter%33 + 1}');
    precacheImage( AssetImage('images/mypic (${_counter%33 + 1}).jpg'), context,onError: (Object exception, StackTrace? stackTrace)=>print('exception:$exception'));
  }

  @override
  void initState() {
    _timer = Timer.periodic(const Duration(seconds: 1), (timer) {
      _pageController.animateToPage((_pageController.page!.toInt() + 1) % 33, duration: Duration(milliseconds: 250), curve: Curves.easeOut);
    });
    super.initState();
  }

  @override
  Widget build(BuildContext context) {

    return Scaffold(
      body: PageView.builder(
        controller: _pageController,
          itemCount: 33,
          onPageChanged: (index){
            precacheImage( AssetImage('images/mypic (${(index + 1)%33 + 1}).jpg'), context,onError: (Object exception, StackTrace? stackTrace)=>print('exception:$exception'));
            precacheImage( AssetImage('images/mypic (${(index + 2)%33 + 1}).jpg'), context,onError: (Object exception, StackTrace? stackTrace)=>print('exception:$exception'));
          },
          itemBuilder: (ctx,index)=>Image.asset('images/mypic (${index + 1}).jpg')
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: _incrementCounter,
        tooltip: 'Increment',
        child: const Icon(Icons.add),
      ), // This trailing comma makes auto-formatting nicer for build methods.
    );
  }
}
```

</details>


### Screenshots or Video

<details open>
<summary>Screenshots / Video demonstration</summary>

![微信图片_20231221131407](https://github.com/flutter/flutter/assets/62126718/6acbd401-bb70-46b6-b4e4-b3c9db49794b)
![微信图片_20231221131843](https://github.com/flutter/flutter/assets/62126718/e26b60ad-1a1c-443a-b1a8-ab365cac1fbd)
![mypic (1)](https://github.com/flutter/flutter/assets/62126718/8b6c89a6-dbd6-4874-bd4a-811cfa4c45bb)

</details>


### Logs

<details open><summary>Logs</summary>

```console
[Paste your logs here]
```

</details>


### Flutter Doctor output

<details open><summary>Doctor output</summary>

```console
[!] Flutter (Channel stable, 3.16.5, on Microsoft Windows [版本 10.0.19045.3803], locale zh-CN)
    • Flutter version 3.16.5 on channel stable at D:\flutter3\flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • FLUTTER_GIT_URL = https://github.com/flutter/flutter.git
    • Framework revision 78666c8dc5 (29 hours ago), 2023-12-19 16:14:14 -0800
    • Engine revision 3f3e560236
    • Dart version 3.2.3
    • DevTools version 2.28.4
    • Pub download mirror https://pub.flutter-io.cn
    • Flutter download mirror https://storage.flutter-io.cn

[√] Windows Version (Installed version of Windows is version 10 or higher)

```

</details>