At this time, if the IrisMethodChannel.dispose not be called explicitly, the native resources created (created via NativeBindingDelegate.createNativeApiEngine) by the IrisMethodChannel can not be cleaned. So the native resources only be cleaned when the APP process is killed.
But by default, the FlutterEngine lifecycle is bound to the android Activity lifecycle. In the single Flutter APP, the FlutterEngine is killed when the whole APP exit(the Activity.onDestory has been called), at this time, the whole APP exit, and the APP process has been killed, so the native resources created by the IrisMethodChannel can be cleaned depending on the process lifecycle.
But in some scenarios, say that start a foreground service in android, when you try to remove the APP from the recent list, the Activity has been removed, the FlutterEngine has been destroyed, but the APP still running (the process not be killed), which will cause the memory leak, and unexpected behavior.
So we need to notify the IrisMethodChannel(dart side) to clean the native resources when the FlutterEngine is destroyed.
At this time, if the
IrisMethodChannel.dispose
not be called explicitly, the native resources created (created viaNativeBindingDelegate.createNativeApiEngine
) by theIrisMethodChannel
can not be cleaned. So the native resources only be cleaned when the APP process is killed.But by default, the
FlutterEngine
lifecycle is bound to the androidActivity
lifecycle. In the single Flutter APP, theFlutterEngine
is killed when the whole APP exit(theActivity.onDestory
has been called), at this time, the whole APP exit, and the APP process has been killed, so the native resources created by theIrisMethodChannel
can be cleaned depending on the process lifecycle.But in some scenarios, say that start a foreground service in android, when you try to remove the APP from the recent list, the
Activity
has been removed, theFlutterEngine
has been destroyed, but the APP still running (the process not be killed), which will cause the memory leak, and unexpected behavior.So we need to notify the
IrisMethodChannel
(dart side) to clean the native resources when theFlutterEngine
is destroyed.