Closed
Description
We‘ve embed Flutter into our existing App. The problem is that we want to release FlutterViewController when there are no Flutter Pages to save some memory. But we found that FlutterViewController can't be released even there are no references to it.
I've debug into Flutter Engine and found that there are some retain circles between FlutterChannels and FlutterViewController. I tried to break the retain circles and released FlutterViewController successfully. But there are some Skia Images leaked during the release of FlutterViewController.
I was wondering is there any official support for FlutterViewController releasing and rebuilding without those memory leak problems.
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel xy_beta_v0.5.6, v0.5.6-pre.112, on Mac OS X 10.13.5 17F77, locale zh-Hans-CN)
[✓] Android toolchain - develop for Android devices (Android SDK 27.0.3)
[✓] iOS toolchain - develop for iOS devices (Xcode 9.4.1)
[✓] Android Studio (version 3.1)
[✓] VS Code (version 1.25.1)
[✓] Connected devices (1 available)
• No issues found!
Metadata
Metadata
Assignees
Labels
Type
Projects
Relationships
Development
No branches or pull requests
Activity
xster commentedon Sep 18, 2018
cc @jamesderlin
seanWongs commentedon Oct 9, 2018
Is there any progress?
jamesderlin commentedon Oct 9, 2018
cc @dnfield
nightwolf-chen commentedon Oct 9, 2018
flutter/engine#6464 This should be related to the retain circles.
dnfield commentedon Oct 9, 2018
flutter/engine#6447 should make this more doable. I'm curious about the Skia images leaking though, do you have a reproduction for that by chance?
nightwolf-chen commentedon Oct 11, 2018
It just happens when you dealloc shell inside FlutterViewController. When I tried to release shell, the Skia Objects unref operation causes a crash for null pointer exceptions. When I tried to avoid the crashes by skipping the unref operation the leaks happened. My guess is that the Skia images have to be released on GPU thread and there were some threads synchronization problems. It could be related to code blow.
shell deconstructor:
unref code:
nightwolf-chen commentedon Oct 11, 2018
Please notice this problem was on 0.5.6 beta version.
dnfield commentedon Oct 16, 2018
Can you try with the code in flutter/engine#6447 and see if you're able to successfully release the view controller without memory leaks? I don't know if I'm doing exactly what you did, but I'm pretty sure it should work with that patch.
9 remaining items