fix memory leak of android view (#50111)

This commit is contained in:
Stonekity
2020-05-22 05:32:03 +08:00
committed by GitHub
parent e92afc16b6
commit 26fabcd41b
2 changed files with 18 additions and 0 deletions

View File

@@ -532,6 +532,7 @@ class AndroidViewController {
await SystemChannels.platform_views.invokeMethod<void>('dispose', id); await SystemChannels.platform_views.invokeMethod<void>('dispose', id);
_platformViewCreatedCallbacks.clear(); _platformViewCreatedCallbacks.clear();
_state = _AndroidViewState.disposed; _state = _AndroidViewState.disposed;
PlatformViewsService._instance._focusCallbacks.remove(id);
} }
/// Sizes the Android View. /// Sizes the Android View.

View File

@@ -85,6 +85,23 @@ void main() {
await viewController.dispose(); await viewController.dispose();
}); });
test('dispose clears focusCallbacks', () async {
bool didFocus = false;
viewsController.registerViewType('webview');
final AndroidViewController viewController = PlatformViewsService.initAndroidView(
id: 0,
viewType: 'webview',
layoutDirection: TextDirection.ltr,
onFocus: () { didFocus = true; }
);
await viewController.setSize(const Size(100.0, 100.0));
await viewController.dispose();
final ByteData message =
SystemChannels.platform_views.codec.encodeMethodCall(const MethodCall('viewFocused', 0));
await SystemChannels.platform_views.binaryMessenger.handlePlatformMessage(SystemChannels.platform_views.name, message, (_) { });
expect(didFocus, isFalse);
});
test('resize Android view', () async { test('resize Android view', () async {
viewsController.registerViewType('webview'); viewsController.registerViewType('webview');
await PlatformViewsService.initAndroidView( await PlatformViewsService.initAndroidView(