@@ -85,10 +85,13 @@ - (instancetype)init __attribute__((unavailable("Use initWithSemanticsObject ins
8585- (instancetype )initWithSemanticsObject : (SemanticsObject*)semanticsObject
8686 bridge : (fml::WeakPtr<shell::AccessibilityBridge>)bridge
8787 NS_DESIGNATED_INITIALIZER;
88+
89+ @property (nonatomic , weak ) SemanticsObject* semanticsObject;
90+
8891@end
8992
9093@implementation SemanticsObject {
91- SemanticsObjectContainer* _container;
94+ fml::scoped_nsobject< SemanticsObjectContainer> _container;
9295}
9396
9497#pragma mark - Override base class designated initializers
@@ -123,8 +126,7 @@ - (void)dealloc {
123126 [_children removeAllObjects ];
124127 [_children release ];
125128 _parent = nil ;
126- [_container release ];
127- _container = nil ;
129+ _container.get ().semanticsObject = nil ;
128130 [super dealloc ];
129131}
130132
@@ -268,9 +270,9 @@ - (CGRect)globalRect {
268270- (id )accessibilityContainer {
269271 if ([self hasChildren ] || [self uid ] == kRootNodeId ) {
270272 if (_container == nil )
271- _container = [[SemanticsObjectContainer alloc ] initWithSemanticsObject: self
272- bridge: [self bridge ]];
273- return _container;
273+ _container. reset ( [[SemanticsObjectContainer alloc ] initWithSemanticsObject: self
274+ bridge: [self bridge ]]) ;
275+ return _container. get () ;
274276 }
275277 if ([self parent ] == nil ) {
276278 // This can happen when we have released the accessibility tree but iOS is
@@ -410,24 +412,17 @@ - (instancetype)init {
410412
411413- (instancetype )initWithSemanticsObject : (SemanticsObject*)semanticsObject
412414 bridge : (fml::WeakPtr<shell::AccessibilityBridge>)bridge {
413- FML_DCHECK (semanticsObject != nil ) << " semanticsObject must be set" ;
415+ FML_DCHECK (semanticsObject) << " semanticsObject must be set" ;
414416 self = [super init ];
415417
416418 if (self) {
417419 _semanticsObject = semanticsObject;
418- // The pointer is managed manually.
419- [_semanticsObject retain ];
420420 _bridge = bridge;
421421 }
422422
423423 return self;
424424}
425425
426- - (void )dealloc {
427- [_semanticsObject release ];
428- [super dealloc ];
429- }
430-
431426#pragma mark - UIAccessibilityContainer overrides
432427
433428- (NSInteger )accessibilityElementCount {
@@ -437,8 +432,9 @@ - (NSInteger)accessibilityElementCount {
437432- (nullable id )accessibilityElementAtIndex : (NSInteger )index {
438433 if (index < 0 || index >= [self accessibilityElementCount ])
439434 return nil ;
440- if (index == 0 )
435+ if (index == 0 ) {
441436 return _semanticsObject;
437+ }
442438 SemanticsObject* child = [_semanticsObject children ][index - 1 ];
443439 if ([child hasChildren ])
444440 return [child accessibilityContainer ];
@@ -506,6 +502,7 @@ - (BOOL)accessibilityScroll:(UIAccessibilityScrollDirection)direction {
506502}
507503
508504AccessibilityBridge::~AccessibilityBridge () {
505+ clearState ();
509506 view_.accessibilityElements = nil ;
510507 [accessibility_channel_.get () setMessageHandler: nil ];
511508}
0 commit comments