Migrate FlutterRestorationPlugin, FlutterTextureRegistryRelay, FlutterScreenAndSceneIfLoaded to ARC (#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.
diff --git a/shell/platform/darwin/ios/BUILD.gn b/shell/platform/darwin/ios/BUILD.gn
index 60f98dd..6515ce6 100644
--- a/shell/platform/darwin/ios/BUILD.gn
+++ b/shell/platform/darwin/ios/BUILD.gn
@@ -61,9 +61,15 @@
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 @@
"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 @@
"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/shell/platform/darwin/ios/framework/Source/FlutterRestorationPlugin.h b/shell/platform/darwin/ios/framework/Source/FlutterRestorationPlugin.h
index dc43717..bb7e1a7 100644
--- a/shell/platform/darwin/ios/framework/Source/FlutterRestorationPlugin.h
+++ b/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/shell/platform/darwin/ios/framework/Source/FlutterRestorationPlugin.mm b/shell/platform/darwin/ios/framework/Source/FlutterRestorationPlugin.mm
index 4e11c4d..d06cba6 100644
--- a/shell/platform/darwin/ios/framework/Source/FlutterRestorationPlugin.mm
+++ b/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 @@
- (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 @@
};
}
-- (void)dealloc {
- [_restorationData release];
- [_pendingRequest release];
- [super dealloc];
-}
-
@end
diff --git a/shell/platform/darwin/ios/framework/Source/FlutterTextureRegistryRelay.h b/shell/platform/darwin/ios/framework/Source/FlutterTextureRegistryRelay.h
index 26c1962..2152ac5 100644
--- a/shell/platform/darwin/ios/framework/Source/FlutterTextureRegistryRelay.h
+++ b/shell/platform/darwin/ios/framework/Source/FlutterTextureRegistryRelay.h
@@ -22,7 +22,7 @@
/**
* A weak reference to a FlutterEngine that will be passed texture registration.
*/
-@property(nonatomic, assign) NSObject<FlutterTextureRegistry>* parent;
+@property(nonatomic, weak) NSObject<FlutterTextureRegistry>* parent;
- (instancetype)initWithParent:(NSObject<FlutterTextureRegistry>*)parent;
@end
diff --git a/shell/platform/darwin/ios/framework/Source/FlutterTextureRegistryRelay.mm b/shell/platform/darwin/ios/framework/Source/FlutterTextureRegistryRelay.mm
index 89377f0..1df2b05 100644
--- a/shell/platform/darwin/ios/framework/Source/FlutterTextureRegistryRelay.mm
+++ b/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/shell/platform/darwin/ios/framework/Source/UIViewController+FlutterScreenAndSceneIfLoaded.mm b/shell/platform/darwin/ios/framework/Source/UIViewController+FlutterScreenAndSceneIfLoaded.mm
index 5eb4f71..b141b65 100644
--- a/shell/platform/darwin/ios/framework/Source/UIViewController+FlutterScreenAndSceneIfLoaded.mm
+++ b/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)