Repository: flutter
Issue: Page with UIKitView has memory leak after popup
Labels: platform-ios,engine,a: platform-views,perf: memory,has reproducible steps,P2,team-ios,triaged-ios,found in release: 3.24,found in release: 3.27

### Steps to reproduce

git clone https://github.com/MQTwist/flutter_uikitview_memory.git
cd flutter_application_1
flutter create .
flutter pub get
open ios/Runner.xcworkspace

### Expected results

On a page with UIKitView, the pop-up system pops up a window, and after the pop-up window is retracted, the memory is released

### Actual results

On a page with UIKitView, the pop-up system pops up a window. After the pop-up window is retracted, the memory is not released. After the page returns, the memory is not released either.

### Code sample

<details open><summary>Code sample</summary>

```dart
import 'package:flutter/material.dart';
import 'package:flutter_application_1/popup_page.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: true,
      ),
      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> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        backgroundColor: Theme.of(context).colorScheme.inversePrimary,
        title: Text(widget.title),
      ),
      body: Center(
        child: ElevatedButton(
            onPressed: () {
              Navigator.push(
                context,
                MaterialPageRoute(
                  builder: (context) {
                    return const PopupPage();
                  },
                ),
              );
            },
            child: const Text("Push")),
      ),
    );
  }
}


import 'package:flutter/material.dart';

class PopupPage extends StatefulWidget {
  const PopupPage({super.key});

  @override
  State<PopupPage> createState() => _PopupPageState();
}

class _PopupPageState extends State<PopupPage> {
  @override
  void initState() {
    super.initState();
    print(">>>flutter PopupPage initState");
  }

  @override
  void dispose() {
    super.dispose();
    print(">>>flutter PopupPage dispose");
  }

  @override
  Widget build(BuildContext context) {
    print(">>>flutter PopupPage build");
    return Scaffold(
      appBar: AppBar(
        title: const Text('DialogPage'),
      ),
      body: Column(
        children: <Widget>[
          const SizedBox(width: double.infinity),
          ElevatedButton(
              onPressed: () {
                _showBottomSheet(context);
              },
              child: const Text("Touch me")),
          const SizedBox(height: 50),
          const SizedBox(
            width: 100,
            height: 100,
            child: UiKitView(viewType: "mqnative"),
          ),
        ],
      ),
    );
  }

  _showBottomSheet(BuildContext context) {
    showModalBottomSheet(
        context: context,
        builder: (context) {
          return Container(
            padding: const EdgeInsets.all(16),
            height: 400,
            child: const Column(
              children: [
                SizedBox(width: double.infinity),
                Text("选择操作"),
              ],
            ),
          );
        });
  }
}


```

</details>


### Screenshots or Video

<details open>
<summary>Screenshots / Video demonstration</summary>

[Upload media here]

</details>


### Logs

<details open><summary>Logs</summary>

```console
2024-10-28 06:22:36.525151+0300 Runner[13213:3887825] flutter: >>>flutter PopupPage initState
2024-10-28 06:22:36.525423+0300 Runner[13213:3887825] flutter: >>>flutter PopupPage build
2024-10-28 06:22:36.527674+0300 Runner[13213:3887587] >>>native MyView init
2024-10-28 06:22:38.193320+0300 Runner[13213:3887825] flutter: >>>flutter PopupPage dispose
2024-10-28 06:22:38.211617+0300 Runner[13213:3887587] >>>native MyView dealloc

```

</details>


### Flutter Doctor output

<details open><summary>Doctor output</summary>

```console
Doctor summary (to see all details, run flutter doctor -v):
[✓] 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.94.2)
[✓] Connected device (4 available)
[✓] Network resources

! Doctor found issues in 1 category.
```

</details>