Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 5e08e4f

Browse files
authored
iOS: Migrate FlutterEngineGroup to ARC (#55503)
This migrates FlutterEngineGroup to automatic reference counting. It also migrates `enginesCreatedCount` from an ivar to property syntax. I'll look at migrating engine from `NSMutableArray<NSValue*>` to a weak pointer array in a followup patch since it's orthogonal to ARC migration. Issue: flutter/flutter#137801 [C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
1 parent def85c7 commit 5e08e4f

File tree

3 files changed

+17
-30
lines changed

3 files changed

+17
-30
lines changed

shell/platform/darwin/ios/BUILD.gn

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ source_set("flutter_framework_source_arc") {
7070
"framework/Source/FlutterDartVMServicePublisher.mm",
7171
"framework/Source/FlutterEmbedderKeyResponder.h",
7272
"framework/Source/FlutterEmbedderKeyResponder.mm",
73+
"framework/Source/FlutterEngineGroup.mm",
7374
"framework/Source/FlutterHeadlessDartRunner.mm",
7475
"framework/Source/FlutterKeyPrimaryResponder.h",
7576
"framework/Source/FlutterKeySecondaryResponder.h",
@@ -182,7 +183,6 @@ source_set("flutter_framework_source") {
182183
# New files are highly encouraged to be in ARC.
183184
# To add new files in ARC, add them to the `flutter_framework_source_arc` target.
184185
"framework/Source/FlutterEngine.mm",
185-
"framework/Source/FlutterEngineGroup.mm",
186186
"framework/Source/FlutterEngine_Internal.h",
187187
"framework/Source/FlutterPlatformPlugin.h",
188188
"framework/Source/FlutterPlatformPlugin.mm",

shell/platform/darwin/ios/framework/Headers/FlutterEngineGroup.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ FLUTTER_DARWIN_EXPORT
3838
/**
3939
* Arguments passed as a list of string to Dart's entrypoint function.
4040
*/
41-
@property(nonatomic, retain, nullable) NSArray<NSString*>* entrypointArgs;
41+
@property(nonatomic, copy, nullable) NSArray<NSString*>* entrypointArgs;
4242
@end
4343

4444
/**

shell/platform/darwin/ios/framework/Source/FlutterEngineGroup.mm

Lines changed: 15 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -5,45 +5,30 @@
55
#import "flutter/shell/platform/darwin/ios/framework/Headers/FlutterEngineGroup.h"
66
#import "flutter/shell/platform/darwin/ios/framework/Source/FlutterEngine_Internal.h"
77

8-
@implementation FlutterEngineGroupOptions
9-
10-
- (void)dealloc {
11-
[_entrypoint release];
12-
[_libraryURI release];
13-
[_initialRoute release];
14-
[_entrypointArgs release];
15-
[super dealloc];
16-
}
8+
FLUTTER_ASSERT_ARC
179

10+
@implementation FlutterEngineGroupOptions
1811
@end
1912

2013
@interface FlutterEngineGroup ()
2114
@property(nonatomic, copy) NSString* name;
22-
@property(nonatomic, retain) NSMutableArray<NSValue*>* engines;
23-
@property(nonatomic, retain) FlutterDartProject* project;
15+
@property(nonatomic, strong) NSMutableArray<NSValue*>* engines;
16+
@property(nonatomic, copy) FlutterDartProject* project;
17+
@property(nonatomic, assign) NSUInteger enginesCreatedCount;
2418
@end
2519

26-
@implementation FlutterEngineGroup {
27-
int _enginesCreatedCount;
28-
}
20+
@implementation FlutterEngineGroup
2921

3022
- (instancetype)initWithName:(NSString*)name project:(nullable FlutterDartProject*)project {
3123
self = [super init];
3224
if (self) {
3325
_name = [name copy];
3426
_engines = [[NSMutableArray<NSValue*> alloc] init];
35-
_project = [project retain];
27+
_project = project;
3628
}
3729
return self;
3830
}
3931

40-
- (void)dealloc {
41-
[_name release];
42-
[_engines release];
43-
[_project release];
44-
[super dealloc];
45-
}
46-
4732
- (FlutterEngine*)makeEngineWithEntrypoint:(nullable NSString*)entrypoint
4833
libraryURI:(nullable NSString*)libraryURI {
4934
return [self makeEngineWithEntrypoint:entrypoint libraryURI:libraryURI initialRoute:nil];
@@ -52,7 +37,7 @@ - (FlutterEngine*)makeEngineWithEntrypoint:(nullable NSString*)entrypoint
5237
- (FlutterEngine*)makeEngineWithEntrypoint:(nullable NSString*)entrypoint
5338
libraryURI:(nullable NSString*)libraryURI
5439
initialRoute:(nullable NSString*)initialRoute {
55-
FlutterEngineGroupOptions* options = [[[FlutterEngineGroupOptions alloc] init] autorelease];
40+
FlutterEngineGroupOptions* options = [[FlutterEngineGroupOptions alloc] init];
5641
options.entrypoint = entrypoint;
5742
options.libraryURI = libraryURI;
5843
options.initialRoute = initialRoute;
@@ -79,7 +64,8 @@ - (FlutterEngine*)makeEngineWithOptions:(nullable FlutterEngineGroupOptions*)opt
7964
initialRoute:initialRoute
8065
entrypointArgs:entrypointArgs];
8166
}
82-
[_engines addObject:[NSValue valueWithPointer:engine]];
67+
// TODO(cbracken): https://github.com/flutter/flutter/issues/155943
68+
[self.engines addObject:[NSValue valueWithPointer:(__bridge void*)engine]];
8369

8470
NSNotificationCenter* center = [NSNotificationCenter defaultCenter];
8571
[center addObserver:self
@@ -91,13 +77,14 @@ - (FlutterEngine*)makeEngineWithOptions:(nullable FlutterEngineGroupOptions*)opt
9177
}
9278

9379
- (FlutterEngine*)makeEngine {
94-
NSString* engineName = [NSString stringWithFormat:@"%@.%d", self.name, ++_enginesCreatedCount];
95-
FlutterEngine* result = [[FlutterEngine alloc] initWithName:engineName project:self.project];
96-
return [result autorelease];
80+
NSString* engineName =
81+
[NSString stringWithFormat:@"%@.%lu", self.name, ++self.enginesCreatedCount];
82+
return [[FlutterEngine alloc] initWithName:engineName project:self.project];
9783
}
9884

9985
- (void)onEngineWillBeDealloced:(NSNotification*)notification {
100-
[_engines removeObject:[NSValue valueWithPointer:notification.object]];
86+
// TODO(cbracken): https://github.com/flutter/flutter/issues/155943
87+
[self.engines removeObject:[NSValue valueWithPointer:(__bridge void*)notification.object]];
10188
}
10289

10390
@end

0 commit comments

Comments
 (0)