flutter_boost
flutter_boost copied to clipboard
内存泄漏
复现步骤:
1、build.gradle中添加‘leakcanary-android:2.9.1’检测库 2、FB自带demo中点击 “open custom view page”。 3、返回键退出。 4、报告有内存泄漏。
log:
┬─── │ GC Root: Input or output parameters in native code │ ├─ dalvik.system.PathClassLoader instance │ Leaking: NO (FlutterEngineCache↓ is not leaking and A ClassLoader is never leaking) │ ↓ ClassLoader.runtimeInternalObjects ├─ java.lang.Object[] array │ Leaking: NO (FlutterEngineCache↓ is not leaking) │ ↓ Object[645] ├─ io.flutter.embedding.engine.FlutterEngineCache class │ Leaking: NO (a class is never leaking) │ ↓ static FlutterEngineCache.instance │ ~~~~~~~~ ├─ io.flutter.embedding.engine.FlutterEngineCache instance │ Leaking: UNKNOWN │ Retaining 140 B in 4 objects │ ↓ FlutterEngineCache.cachedEngines │ ~~~~~~~~~~~~~ ├─ java.util.HashMap instance │ Leaking: UNKNOWN │ Retaining 128 B in 3 objects │ ↓ HashMap["flutter_boost_default_engine"] │ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ├─ io.flutter.embedding.engine.FlutterEngine instance │ Leaking: UNKNOWN │ Retaining 5.2 kB in 142 objects │ ↓ FlutterEngine.platformViewsController │ ~~~~~~~~~~~~~~~~~~~~~~~ ├─ io.flutter.plugin.platform.PlatformViewsController instance │ Leaking: UNKNOWN │ Retaining 680 B in 21 objects │ context instance of com.idlefish.flutterboost.example.tab.TabCustomViewActivity with mDestroyed = true │ ↓ PlatformViewsController.context │ ~~~~~~~ ╰→ com.idlefish.flutterboost.example.tab.TabCustomViewActivity instance Leaking: YES (ObjectWatcher was watching this because com.idlefish.flutterboost.example.tab.TabCustomViewActivity received Activity#onDestroy() callback and Activity#mDestroyed is true) Retaining 45.0 kB in 773 objects key = 67860805-c7c7-41f4-a33d-c548975d52ec watchDurationMillis = 6707 retainedDurationMillis = 1665 mApplication instance of com.idlefish.flutterboost.example.MyApplication mBase instance of android.app.ContextImpl
环境
Flutter Boost Version:4.2.0 Target Platform: Android Target OS version/browser: android 10 Devices: Android模拟器
flutter doctor -v
:
[✓] Flutter (Channel stable, 3.0.5, on macOS 13.1 22C65 darwin-arm, locale zh-Hans-CN)
• Flutter version 3.0.5 at /Users/zfn/workspace/flutter/sdk/google/flutter-3.0.5
• Upstream repository https://github.com/flutter/flutter.git
• FLUTTER_GIT_URL = https://gitee.com/mirrors/Flutter.git
• Framework revision f1875d570e (7 months ago), 2022-07-13 11:24:16 -0700
• Engine revision e85ea0e79c
• Dart version 2.17.6
• DevTools version 2.12.2
• Pub download mirror https://pub.flutter-io.cn
• Flutter download mirror https://storage.flutter-io.cn
[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.1)
• Android SDK at /Users/zfn/Library/Android/sdk
• Platform android-33, build-tools 33.0.1
• ANDROID_HOME = /Users/zfn/Library/Android/sdk
• Java binary at: /Library/Java/JavaVirtualMachines/jdk1.8.0_321.jdk/Contents/Home/bin/java
• Java version Java(TM) SE Runtime Environment (build 1.8.0_321-b07)
• All Android licenses accepted.
这个主要是普通Activity+FlutterBoostView的实现下,FlutterBoostView在onDestroy下并不会去触发PlatformViewsController.detach()
方法,所以不会销毁其中的context
。使用FlutterBoostActivity或FlutterBoostFragment应该都没问题
如果确认使用FlutterBoostView的Activity销毁时,没有其他Flutter页面,可以手动调用FlutterBoost.instance().getEngine().getPlatformViewsController().detach();
最好不要用FlutterBoostView吧,问题很多。