From 3cd96ea83c1326381d6a6c759a3c9c25ecd011e4 Mon Sep 17 00:00:00 2001 From: Jenn Magder Date: Wed, 10 Apr 2024 14:53:51 -0700 Subject: [PATCH] Migrate FlutterRestorationPlugin, FlutterTextureRegistryRelay, FlutterScreenAndSceneIfLoaded to ARC (flutter/engine#51984) Smart pointers support ARC as of https://github.com/flutter/engine/pull/47612, and the unit tests were migrated in https://github.com/flutter/engine/pull/48162. Migrate `FlutterRestorationPlugin`, `FlutterTextureRegistryRelay`, and `UIViewController+FlutterScreenAndSceneIfLoaded` from MRC to ARC. These files do not themselves import any MRC files, making them leaf nodes in the dependency graph of MRC files. Doing a few at a time to make the dependency graph manageable, and to easily revert if this causes retain cycles or other memory management issues. Part of https://github.com/flutter/flutter/issues/137801. --- .../src/flutter/shell/platform/darwin/ios/BUILD.gn | 12 ++++++------ .../ios/framework/Source/FlutterRestorationPlugin.h | 2 +- .../ios/framework/Source/FlutterRestorationPlugin.mm | 11 ++--------- .../framework/Source/FlutterTextureRegistryRelay.h | 2 +- .../framework/Source/FlutterTextureRegistryRelay.mm | 2 ++ ...UIViewController+FlutterScreenAndSceneIfLoaded.mm | 3 +++ 6 files changed, 15 insertions(+), 17 deletions(-) diff --git a/engine/src/flutter/shell/platform/darwin/ios/BUILD.gn b/engine/src/flutter/shell/platform/darwin/ios/BUILD.gn index 60f98dd61d..6515ce60a8 100644 --- a/engine/src/flutter/shell/platform/darwin/ios/BUILD.gn +++ b/engine/src/flutter/shell/platform/darwin/ios/BUILD.gn @@ -61,9 +61,15 @@ source_set("flutter_framework_source_arc") { sources = [ "framework/Source/FlutterMetalLayer.h", "framework/Source/FlutterMetalLayer.mm", + "framework/Source/FlutterRestorationPlugin.h", + "framework/Source/FlutterRestorationPlugin.mm", "framework/Source/FlutterTextInputDelegate.h", "framework/Source/FlutterTextInputPlugin.h", "framework/Source/FlutterTextInputPlugin.mm", + "framework/Source/FlutterTextureRegistryRelay.h", + "framework/Source/FlutterTextureRegistryRelay.mm", + "framework/Source/UIViewController+FlutterScreenAndSceneIfLoaded.h", + "framework/Source/UIViewController+FlutterScreenAndSceneIfLoaded.mm", ] frameworks = [ @@ -110,14 +116,10 @@ source_set("flutter_framework_source") { "framework/Source/FlutterPlatformViews_Internal.h", "framework/Source/FlutterPlatformViews_Internal.mm", "framework/Source/FlutterPluginAppLifeCycleDelegate.mm", - "framework/Source/FlutterRestorationPlugin.h", - "framework/Source/FlutterRestorationPlugin.mm", "framework/Source/FlutterSemanticsScrollView.h", "framework/Source/FlutterSemanticsScrollView.mm", "framework/Source/FlutterSpellCheckPlugin.h", "framework/Source/FlutterSpellCheckPlugin.mm", - "framework/Source/FlutterTextureRegistryRelay.h", - "framework/Source/FlutterTextureRegistryRelay.mm", "framework/Source/FlutterUIPressProxy.h", "framework/Source/FlutterUIPressProxy.mm", "framework/Source/FlutterUndoManagerDelegate.h", @@ -131,8 +133,6 @@ source_set("flutter_framework_source") { "framework/Source/KeyCodeMap_Internal.h", "framework/Source/SemanticsObject.h", "framework/Source/SemanticsObject.mm", - "framework/Source/UIViewController+FlutterScreenAndSceneIfLoaded.h", - "framework/Source/UIViewController+FlutterScreenAndSceneIfLoaded.mm", "framework/Source/accessibility_bridge.h", "framework/Source/accessibility_bridge.mm", "framework/Source/accessibility_text_entry.h", diff --git a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterRestorationPlugin.h b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterRestorationPlugin.h index dc437179c9..bb7e1a7873 100644 --- a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterRestorationPlugin.h +++ b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterRestorationPlugin.h @@ -15,7 +15,7 @@ - (instancetype)initWithChannel:(FlutterMethodChannel*)channel restorationEnabled:(BOOL)waitForData NS_DESIGNATED_INITIALIZER; -@property(nonatomic, strong) NSData* restorationData; +@property(nonatomic, copy) NSData* restorationData; - (void)markRestorationComplete; - (void)reset; @end diff --git a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterRestorationPlugin.mm b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterRestorationPlugin.mm index 4e11c4d19a..d06cba6c79 100644 --- a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterRestorationPlugin.mm +++ b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterRestorationPlugin.mm @@ -9,7 +9,7 @@ #include "flutter/fml/logging.h" -FLUTTER_ASSERT_NOT_ARC +FLUTTER_ASSERT_ARC @interface FlutterRestorationPlugin () @property(nonatomic, copy) FlutterResult pendingRequest; @@ -54,8 +54,7 @@ FLUTTER_ASSERT_NOT_ARC - (void)setRestorationData:(NSData*)data { if (data != _restorationData) { - [_restorationData release]; - _restorationData = [data retain]; + _restorationData = [data copy]; } _waitForData = NO; if (self.pendingRequest != nil) { @@ -91,10 +90,4 @@ FLUTTER_ASSERT_NOT_ARC }; } -- (void)dealloc { - [_restorationData release]; - [_pendingRequest release]; - [super dealloc]; -} - @end diff --git a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterTextureRegistryRelay.h b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterTextureRegistryRelay.h index 26c19621fc..2152ac55a3 100644 --- a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterTextureRegistryRelay.h +++ b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterTextureRegistryRelay.h @@ -22,7 +22,7 @@ FLUTTER_DARWIN_EXPORT /** * A weak reference to a FlutterEngine that will be passed texture registration. */ -@property(nonatomic, assign) NSObject* parent; +@property(nonatomic, weak) NSObject* parent; - (instancetype)initWithParent:(NSObject*)parent; @end diff --git a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterTextureRegistryRelay.mm b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterTextureRegistryRelay.mm index 89377f0b4b..1df2b05c45 100644 --- a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterTextureRegistryRelay.mm +++ b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterTextureRegistryRelay.mm @@ -6,6 +6,8 @@ #include "flutter/fml/logging.h" +FLUTTER_ASSERT_ARC + @implementation FlutterTextureRegistryRelay : NSObject #pragma mark - FlutterTextureRegistry diff --git a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/UIViewController+FlutterScreenAndSceneIfLoaded.mm b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/UIViewController+FlutterScreenAndSceneIfLoaded.mm index 5eb4f71103..b141b65768 100644 --- a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/UIViewController+FlutterScreenAndSceneIfLoaded.mm +++ b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/UIViewController+FlutterScreenAndSceneIfLoaded.mm @@ -5,6 +5,9 @@ #import "flutter/shell/platform/darwin/ios/framework/Source/UIViewController+FlutterScreenAndSceneIfLoaded.h" #include "flutter/fml/logging.h" +#import "flutter/shell/platform/darwin/common/framework/Headers/FlutterMacros.h" + +FLUTTER_ASSERT_ARC @implementation UIViewController (FlutterScreenAndSceneIfLoaded)