Repository: flutter
Issue: FlutterPluginRegistry may leak onViewDestroyListeners
Labels: platform-android,engine,c: performance,perf: memory,P3,team-android,triaged-android

Based on the latest dev build (1.12.11), code like this:

``` kotlin
@JvmStatic
fun registerWith(registrar: Registrar) {
    val plugin = MyPlugin(registrar.context(), registrar.messenger())

    val methodChannel = MethodChannel(registrar.messenger(), "$NAMESPACE/methods")
    methodChannel.setMethodCallHandler(plugin)

    registrar.addViewDestroyListener {
        plugin.onViewDestroyed()
        false
    }
}
```

May lead to a ever-growing `FlutterPluginRegistry.mViewDestroyListeners` array.
https://github.com/flutter/engine/blob/647a8524b0d722a4a2ce976adb5ed9c981e61b82/shell/platform/android/io/flutter/app/FlutterPluginRegistry.java#L46

When the view is destroyed, would it not suffice to just clear the list of view destroy listeners in https://github.com/flutter/engine/blob/647a8524b0d722a4a2ce976adb5ed9c981e61b82/shell/platform/android/io/flutter/app/FlutterPluginRegistry.java#L239 ?

This can be easily reproduced by switching the "Don't keep activities" setting on in the Android developer settings.

![Screenshot_20191124-175802](https://user-images.githubusercontent.com/269860/69498893-af069d00-0ee4-11ea-9cd9-0ea05a9673a0.png)

PS: On a side note, it seems now necessary to also unregister the message handler, else that will leak as well:

``` kotlin
registrar.addViewDestroyListener {
    registrar.messenger().setMessageHandler("$NAMESPACE/methods", null)     // required?
    methodChannel.setMethodCallHandler(null)
    plugin.onViewDestroyed()
    false
}
```

```
% flutter doctor -v
[✓] Flutter (Channel dev, v1.12.11, on Mac OS X 10.15.1 19B88, locale en-US)
    • Flutter version 1.12.11 at /Users/ened/dev/flutter
    • Framework revision f40dbf8ca0 (2 days ago), 2019-11-23 01:02:54 -0500
    • Engine revision d1cac77d5a
    • Dart version 2.7.0

 
[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
    • Android SDK at /usr/local/share/android-sdk
    • Android NDK location not configured (optional; useful for native profiling support)
    • Platform android-29, build-tools 29.0.2
    • ANDROID_HOME = /usr/local/share/android-sdk
    • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b49-5587405)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 11.2)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 11.2, Build version 11B52
    • CocoaPods version 1.8.4

[✓] Android Studio (version 3.5)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin version 41.1.2
    • Dart plugin version 191.8593
    • Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b49-5587405)

[✓] VS Code (version 1.39.2)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.6.0

[✓] Connected device (1 available)
    • Pixel 2 • HT83G1A03545 • android-arm64 • Android 10 (API 29)

• No issues found!
```