I’m using a flutter module for a small, infrequently used portion of a pre existing iOS and android app. I’m trying to deal with memory management issues. It seems like there’s no documented way to best release the flutter engine and it’s complicated by having to use the plugin registrar which I believe to be holding on a reference to the engine in some black box. Does anyone have experience with using a module in such a limited context?
On iOS I have tried the following:
- call
destroyContextonViewDidDisasppear - initialize Flutter Engine in VC and set to nil on
ViewDidDisappear - initialize Flutter Engine outside of VC on AppDelegate and set to nil on ViewDidDisappear
- Tried both creating engine and non specified engine when creating Flutter VC
On Android I am using a FlutterView and have tried the following:
- Tried running engine.Destroy on destroy function of activity
- Run the following code on the destroy lifecycle function:
private void unhookActivityAndView() {
activity.getLifecycle().removeObserver(this);
engine.getActivityControlSurface().detachFromActivity();
platformPlugin.destroy();
platformPlugin = null;
engine.getLifecycleChannel().appIsDetached();
flutterView.detachFromFlutterEngine();
//engine.destroy();
}
In all of the above scenarios it seems that the Apps would not release the Fluter resources, and every time I navigate back and reinitialize the flutter module the memory usage would rise.
Is there a better way to be managing the Flutter resources in order to prevent this engine, or other flutter resources, persist in memory?