From a4bb83e6e8bfe5d97799d56d24f3bc13bd06aa0c Mon Sep 17 00:00:00 2001 From: Chris Bracken Date: Wed, 30 Oct 2024 17:37:26 -0700 Subject: [PATCH] iOS: Eliminate strong retain loop in Scenario tests (flutter/engine#56249) `FlutterViewControllerTest testDrawLayer` created a callback which strongly referenced itself in its own body as part of an asynchronous recursive loop. The recursion was unnecessary and the test consistently passes, even if run on repeat > 100 times without it. Now that there's only one call, eliminates the unnecessary local and inlines it into the `dispatch_after` call. This was originally introduced in https://github.com/flutter/engine/pull/50072. [C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style --- .../ScenariosTests/FlutterViewControllerTest.m | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/engine/src/flutter/testing/scenario_app/ios/Scenarios/ScenariosTests/FlutterViewControllerTest.m b/engine/src/flutter/testing/scenario_app/ios/Scenarios/ScenariosTests/FlutterViewControllerTest.m index 533b4153af..339e0d7c00 100644 --- a/engine/src/flutter/testing/scenario_app/ios/Scenarios/ScenariosTests/FlutterViewControllerTest.m +++ b/engine/src/flutter/testing/scenario_app/ios/Scenarios/ScenariosTests/FlutterViewControllerTest.m @@ -91,9 +91,7 @@ FLUTTER_ASSERT_ARC [rootVC presentViewController:self.flutterViewController animated:NO completion:nil]; CGColorSpaceRef color_space = CGColorSpaceCreateDeviceRGB(); - - __block dispatch_block_t callback; - callback = ^{ + dispatch_after(dispatch_time(DISPATCH_TIME_NOW, NSEC_PER_SEC), dispatch_get_main_queue(), ^{ size_t width = 300u; CGContextRef context = CGBitmapContextCreate(nil, width, width, 8, 4 * width, color_space, @@ -104,14 +102,8 @@ FLUTTER_ASSERT_ARC [imageRendered fulfill]; return; } - CGContextRelease(context); - - dispatch_after(dispatch_time(DISPATCH_TIME_NOW, NSEC_PER_SEC), dispatch_get_main_queue(), - callback); - }; - dispatch_after(dispatch_time(DISPATCH_TIME_NOW, NSEC_PER_SEC), dispatch_get_main_queue(), - callback); + }); [self waitForExpectationsWithTimeout:30.0 handler:nil];