Fixes FlutterEngine internal retain cycle (flutter/engine#18595)

This commit is contained in:
Wu Zhong
2020-06-18 06:33:49 +08:00
committed by GitHub
parent da60e68f07
commit bce3b9c2a2
2 changed files with 21 additions and 5 deletions

View File

@@ -396,17 +396,22 @@ static constexpr int kNumProfilerSamplesPerSec = 5;
- (void)maybeSetupPlatformViewChannels {
if (_shell && self.shell.IsSetup()) {
FlutterPlatformPlugin* platformPlugin = _platformPlugin.get();
[_platformChannel.get() setMethodCallHandler:^(FlutterMethodCall* call, FlutterResult result) {
[_platformPlugin.get() handleMethodCall:call result:result];
[platformPlugin handleMethodCall:call result:result];
}];
fml::WeakPtr<FlutterEngine> weakSelf = [self getWeakPtr];
[_platformViewsChannel.get()
setMethodCallHandler:^(FlutterMethodCall* call, FlutterResult result) {
_platformViewsController->OnMethodCall(call, result);
if (weakSelf) {
weakSelf.get().platformViewsController->OnMethodCall(call, result);
}
}];
FlutterTextInputPlugin* textInputPlugin = _textInputPlugin.get();
[_textInputChannel.get() setMethodCallHandler:^(FlutterMethodCall* call, FlutterResult result) {
[_textInputPlugin.get() handleMethodCall:call result:result];
[textInputPlugin handleMethodCall:call result:result];
}];
}
}

View File

@@ -9,10 +9,10 @@
FLUTTER_ASSERT_ARC
@interface FlutteEngineTest : XCTestCase
@interface FlutterEngineTest : XCTestCase
@end
@implementation FlutteEngineTest
@implementation FlutterEngineTest
- (void)setUp {
}
@@ -26,6 +26,17 @@ FLUTTER_ASSERT_ARC
XCTAssertNotNil(engine);
}
- (void)testDeallocated {
__weak FlutterEngine* weakEngine = nil;
{
FlutterEngine* engine = [[FlutterEngine alloc] initWithName:@"foobar"];
weakEngine = engine;
[engine run];
XCTAssertNotNil(weakEngine);
}
XCTAssertNil(weakEngine);
}
- (void)testSendMessageBeforeRun {
id project = OCMClassMock([FlutterDartProject class]);
FlutterEngine* engine = [[FlutterEngine alloc] initWithName:@"foobar" project:project];