alibaba / alibaba/flutter_boost

[Bug]: iOS: 原生控制器嵌入一块FBFlutterViewContainer,当控制器返回时原生控制器走了deinit,但是FBFlutterViewContainer没有释放

Open
#2,227 4 comments 0 reactions 0 assignees View on GitHub
Dominant language
Dart
Stars
7.2k
Forks
1.3k
PR merge metrics
No merged PRs in 30d

Description

### 请描述遇到的问题,以及您所期望的正确的结果

flutter version: 3.10.6
iOS : swift

一个原生控制器,上半部分是原生的,下半部分嵌入一块FBFlutterViewContainer,当返回时该原生控制器走了deinit,但是 FBFlutterViewContainer没有走 dealloc 。期望 FBFlutterViewContainer 能够正常释放。

### 请说明如何操作会遇到上述问题

_No response_

### 在下面填入关键复现代码

//
// NativeViewController.swift
// Runner
//
// Created by Apple on 2025/8/19.
//

import Foundation
import UIKit
import flutter_boost
import MCommonBiz

class NativeViewController: MCBaseViewController {
var flutterContainer: FBFlutterViewContainer?

override func viewDidLoad() {
super.viewDidLoad()
self.title = "测试"
setupFlutterView()
}

private func setupFlutterView() {
// 创建 Flutter 容器
let container = FBFlutterViewContainer()
container?.setName("catalog/detail", uniqueId: nil, params: nil, opaque: true)

// 添加为子控制器
addChild(container!)
view.addSubview(container!.view)
container?.didMove(toParent: self)
container?.view.frame = CGRect(x: 0,
y: 200,
width: Screen.width,
height: Screen.height - 200)

self.flutterContainer = container
}

deinit {
flutterContainer?.detachFlutterEngineIfNeeded()
flutterContainer?.notifyWillDealloc()
flutterContainer?.removeFromParent()
flutterContainer?.view.removeFromSuperview()
flutterContainer = nil
print("✅ NativeViewController deallocated")
}
}

### 复现的平台

iOS

### Flutter SDK版本

3.10.6

### FlutterBoost版本

4.6.3

### 是否延迟初始化FlutterBoost

No

### 解决方案

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with the NativeViewController.swift reproduction and the FBFlutterViewContainer lifecycle in FlutterBoost 4.6.3. Reproduce the iOS navigation flow using Flutter 3.10.6, then inspect the effects of detachFlutterEngineIfNeeded, notifyWillDealloc, and removeFromParent. Done means FBFlutterViewContainer is released after the native controller returns.

Written by the indexing model from the issue text.

Assessment

Tech stack
dart, ios, swift
Domain
mobile-dev
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.