Fixed memory leaks within FlutterFragment and FlutterView (#34268, #34269, #34270). (flutter/engine#9288)

This commit is contained in:
Matt Carroll
2019-06-11 17:01:20 -07:00
committed by GitHub
parent fe0db192d9
commit fb2826eb79
4 changed files with 18 additions and 3 deletions

View File

@@ -607,6 +607,7 @@ public class FlutterFragment extends Fragment {
// Null out the platformPlugin to avoid a possible retain cycle between the plugin, this Fragment,
// and this Fragment's Activity.
platformPlugin.destroy();
platformPlugin = null;
// Destroy our FlutterEngine if we're not set to retain it.

View File

@@ -561,11 +561,16 @@ public class FlutterView extends FrameLayout {
}
Log.d(TAG, "Detaching from Flutter Engine");
// Disconnect and clean up the AccessibilityBridge.
accessibilityBridge.release();
accessibilityBridge = null;
// Inform the Android framework that it should retrieve a new InputConnection
// now that the engine is detached. The new InputConnection will be null, which
// signifies that this View does not process input (until a new engine is attached).
// TODO(mattcarroll): once this is proven to work, move this line ot TextInputPlugin
textInputPlugin.getInputMethodManager().restartInput(this);
textInputPlugin.destroy();
// Instruct our FlutterRenderer that we are no longer interested in being its RenderSurface.
didRenderFirstFrame = false;

View File

@@ -46,7 +46,7 @@ public class TextInputPlugin {
// target is a platform view. See the comments on lockPlatformViewInputConnection for more details.
private boolean isInputConnectionLocked;
// TODO(mattcarroll): change @Nullable to @NonNull once new embedding integrates PlatformViewsController.
// TODO(mattcarroll): change @Nullable to @NonNull once new embedding integrates PlatformViewsController (#34286).
public TextInputPlugin(View view, @NonNull DartExecutor dartExecutor, @Nullable PlatformViewsController platformViewsController) {
mView = view;
mImm = (InputMethodManager) view.getContext().getSystemService(
@@ -85,7 +85,7 @@ public class TextInputPlugin {
}
});
this.platformViewsController = platformViewsController;
// TODO(mattcarroll): remove if-statement once new embedding integrates PlatformViewsController.
// TODO(mattcarroll): remove if-statement once new embedding integrates PlatformViewsController (#34286).
if (platformViewsController != null) {
platformViewsController.attachTextInputPlugin(this);
}
@@ -127,7 +127,7 @@ public class TextInputPlugin {
* The TextInputPlugin instance should not be used after calling this.
*/
public void destroy() {
// TODO(mattcarroll): Remove if-statement once new embedding integrates PlatformViewsController.
// TODO(mattcarroll): Remove if-statement once new embedding integrates PlatformViewsController (#34286).
if (platformViewsController != null) {
platformViewsController.detachTextInputPlugin();
}

View File

@@ -94,6 +94,15 @@ public class PlatformPlugin implements ActivityLifecycleListener {
mEnabledOverlays = DEFAULT_SYSTEM_UI;
}
/**
* Releases all resources held by this {@code PlatformPlugin}.
* <p>
* Do not invoke any methods on a {@code PlatformPlugin} after invoking this method.
*/
public void destroy() {
this.platformChannel.setPlatformMessageHandler(null);
}
private void playSystemSound(PlatformChannel.SoundType soundType) {
if (soundType == PlatformChannel.SoundType.CLICK) {
View view = activity.getWindow().getDecorView();