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

Commit 5606040

Browse files
committed
Fix UIWindowSceneGeometryPreferencesIOS leak
1 parent c78ef3b commit 5606040

File tree

2 files changed

+42
-36
lines changed

2 files changed

+42
-36
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1814,8 +1814,8 @@ - (void)performOrientationUpdate:(UIInterfaceOrientationMask)new_preferences {
18141814
}
18151815
UIWindowScene* windowScene = (UIWindowScene*)scene;
18161816
UIWindowSceneGeometryPreferencesIOS* preference =
1817-
[[UIWindowSceneGeometryPreferencesIOS alloc]
1818-
initWithInterfaceOrientations:_orientationPreferences];
1817+
[[[UIWindowSceneGeometryPreferencesIOS alloc]
1818+
initWithInterfaceOrientations:_orientationPreferences] autorelease];
18191819
[windowScene
18201820
requestGeometryUpdateWithPreferences:preference
18211821
errorHandler:^(NSError* error) {

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

Lines changed: 40 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1341,47 +1341,53 @@ - (void)orientationTestWithOrientationUpdate:(UIInterfaceOrientationMask)mask
13411341
id mockApplication = OCMClassMock([UIApplication class]);
13421342
id mockWindowScene;
13431343
id deviceMock;
1344-
FlutterViewController* realVC = [[FlutterViewController alloc] initWithEngine:self.mockEngine
1345-
nibName:nil
1346-
bundle:nil];
1347-
if (@available(iOS 16.0, *)) {
1348-
mockWindowScene = OCMClassMock([UIWindowScene class]);
1349-
if (realVC.supportedInterfaceOrientations == mask) {
1350-
OCMReject([mockWindowScene requestGeometryUpdateWithPreferences:[OCMArg any]
1351-
errorHandler:[OCMArg any]]);
1344+
__block __weak id weakPreferences;
1345+
@autoreleasepool {
1346+
FlutterViewController* realVC = [[FlutterViewController alloc] initWithEngine:self.mockEngine
1347+
nibName:nil
1348+
bundle:nil];
1349+
if (@available(iOS 16.0, *)) {
1350+
mockWindowScene = OCMClassMock([UIWindowScene class]);
1351+
if (realVC.supportedInterfaceOrientations == mask) {
1352+
OCMReject([mockWindowScene requestGeometryUpdateWithPreferences:[OCMArg any]
1353+
errorHandler:[OCMArg any]]);
1354+
} else {
1355+
// iOS 16 will decide whether to rotate based on the new preference, so always set it
1356+
// when it changes.
1357+
OCMExpect([mockWindowScene
1358+
requestGeometryUpdateWithPreferences:[OCMArg checkWithBlock:^BOOL(
1359+
UIWindowSceneGeometryPreferencesIOS*
1360+
preferences) {
1361+
weakPreferences = preferences;
1362+
return preferences.interfaceOrientations == mask;
1363+
}]
1364+
errorHandler:[OCMArg any]]);
1365+
}
1366+
OCMStub([mockApplication sharedApplication]).andReturn(mockApplication);
1367+
OCMStub([mockApplication connectedScenes]).andReturn([NSSet setWithObject:mockWindowScene]);
13521368
} else {
1353-
// iOS 16 will decide whether to rotate based on the new preference, so always set it
1354-
// when it changes.
1355-
OCMExpect([mockWindowScene
1356-
requestGeometryUpdateWithPreferences:[OCMArg checkWithBlock:^BOOL(
1357-
UIWindowSceneGeometryPreferencesIOS*
1358-
preferences) {
1359-
return preferences.interfaceOrientations == mask;
1360-
}]
1361-
errorHandler:[OCMArg any]]);
1369+
deviceMock = OCMPartialMock([UIDevice currentDevice]);
1370+
if (!didChange) {
1371+
OCMReject([deviceMock setValue:[OCMArg any] forKey:@"orientation"]);
1372+
} else {
1373+
OCMExpect([deviceMock setValue:@(resultingOrientation) forKey:@"orientation"]);
1374+
}
1375+
1376+
OCMStub([mockApplication sharedApplication]).andReturn(mockApplication);
1377+
OCMStub([mockApplication statusBarOrientation]).andReturn(currentOrientation);
13621378
}
1363-
OCMStub([mockApplication sharedApplication]).andReturn(mockApplication);
1364-
OCMStub([mockApplication connectedScenes]).andReturn([NSSet setWithObject:mockWindowScene]);
1365-
} else {
1366-
deviceMock = OCMPartialMock([UIDevice currentDevice]);
1367-
if (!didChange) {
1368-
OCMReject([deviceMock setValue:[OCMArg any] forKey:@"orientation"]);
1379+
1380+
[realVC performOrientationUpdate:mask];
1381+
if (@available(iOS 16.0, *)) {
1382+
OCMVerifyAll(mockWindowScene);
13691383
} else {
1370-
OCMExpect([deviceMock setValue:@(resultingOrientation) forKey:@"orientation"]);
1384+
OCMVerifyAll(deviceMock);
13711385
}
1372-
1373-
OCMStub([mockApplication sharedApplication]).andReturn(mockApplication);
1374-
OCMStub([mockApplication statusBarOrientation]).andReturn(currentOrientation);
1375-
}
1376-
1377-
[realVC performOrientationUpdate:mask];
1378-
if (@available(iOS 16.0, *)) {
1379-
OCMVerifyAll(mockWindowScene);
1380-
} else {
1381-
OCMVerifyAll(deviceMock);
13821386
}
1387+
[mockWindowScene stopMocking];
13831388
[deviceMock stopMocking];
13841389
[mockApplication stopMocking];
1390+
XCTAssertNil(weakPreferences);
13851391
}
13861392

13871393
// Creates a mocked UITraitCollection with nil values for everything except accessibilityContrast,

0 commit comments

Comments
 (0)