Break retain cycle in RCTScrollViewComponentView

Summary: Breaks cycle by making self weak and storing delegates weakly.

Reviewed By: fkgozali

Differential Revision: D16579754

fbshipit-source-id: 17174b0e91898a14a86b8b44677090be3044382d
This commit is contained in:
Samuel Susla
2019-07-31 10:05:28 -07:00
committed by Facebook Github Bot
parent 6764385c80
commit 14edd5d634
2 changed files with 5 additions and 4 deletions
@@ -53,8 +53,9 @@ using namespace facebook::react;
_containerView = [[UIView alloc] initWithFrame:CGRectZero];
[_scrollView addSubview:_containerView];
__weak __typeof(self) weakSelf = self;
_scrollViewDelegateSplitter = [[RNGenericDelegateSplitter alloc] initWithDelegateUpdateBlock:^(id delegate) {
self->_scrollView.delegate = delegate;
weakSelf.scrollView.delegate = delegate;
}];
[_scrollViewDelegateSplitter addDelegate:self];
@@ -8,7 +8,7 @@
#import "RNGenericDelegateSplitter.h"
@implementation RNGenericDelegateSplitter {
NSMutableArray *_delegates;
NSHashTable *_delegates;
}
#pragma mark - Public
@@ -17,7 +17,7 @@
{
if (self = [super init]) {
_delegateUpdateBlock = block;
_delegates = [NSMutableArray new];
_delegates = [NSHashTable weakObjectsHashTable];
}
return self;
@@ -44,7 +44,7 @@
return;
}
_delegateUpdateBlock(_delegates.count == 1 ? _delegates.firstObject : self);
_delegateUpdateBlock(_delegates.count == 1 ? [_delegates allObjects].firstObject : self);
}
#pragma mark - Fast Forwarding