Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 29 additions & 2 deletions shell/platform/darwin/ios/framework/Source/SemanticsObject.mm
Original file line number Diff line number Diff line change
Expand Up @@ -571,15 +571,42 @@ - (instancetype)initWithSemanticsObject:(SemanticsObject*)object {
}

- (void)dealloc {
[_semanticsObject release];

@chunhtai chunhtai Feb 9, 2021

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if the FlutterPlatformViewSemanticsContainer does not own the semantics object, it should not release it? also the property is declared as assign, it should not increase the reference count.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cc @gaaclarke who is more familiar with reference counting

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oops good catch! This code was there for debugging and I forgot to remove it. Removed now

_semanticsObject = nil;
[_platformView release];
_platformView = nil;
[super dealloc];
}

- (NSArray*)accessibilityElements {
return @[ _semanticsObject, _platformView ];
#pragma mark - UIAccessibilityContainer overrides

- (NSInteger)accessibilityElementCount {
// This container should only contain 2 elements:
// 1. The semantic object that represents this container.
// 2. The platform view object.
return 2;
}

- (nullable id)accessibilityElementAtIndex:(NSInteger)index {
FML_DCHECK(index < 2);
if (index == 0) {
return _semanticsObject;
} else {
return _platformView;
}
}

- (NSInteger)indexOfAccessibilityElement:(id)element {
FML_DCHECK(element == _semanticsObject || element == _platformView);
if (element == _semanticsObject) {
return 0;
} else {
return 1;
}
}

#pragma mark - UIAccessibilityElement overrides

- (CGRect)accessibilityFrame {
return _semanticsObject.accessibilityFrame;
}
Expand Down
12 changes: 12 additions & 0 deletions shell/platform/darwin/ios/framework/Source/SemanticsObjectTest.mm
Original file line number Diff line number Diff line change
Expand Up @@ -217,4 +217,16 @@ - (void)testShouldDispatchShowOnScreenActionForHidden {
XCTAssertTrue(bridge->observations[0].action == flutter::SemanticsAction::kShowOnScreen);
}

- (void)testSemanticsObjectAndPlatformViewSemanticsContainerDontHaveRetainCycle {
fml::WeakPtrFactory<flutter::MockAccessibilityBridge> factory(
new flutter::MockAccessibilityBridge());
fml::WeakPtr<flutter::MockAccessibilityBridge> bridge = factory.GetWeakPtr();
SemanticsObject* object = [[SemanticsObject alloc] initWithBridge:bridge uid:1];
object.platformViewSemanticsContainer =
[[FlutterPlatformViewSemanticsContainer alloc] initWithSemanticsObject:object];
__weak SemanticsObject* weakObject = object;
object = nil;
XCTAssertNil(weakObject);
}

@end