Skip to content

Commit 5e6c61e

Browse files
sherginfacebook-github-bot
authored andcommittedJan 13, 2020
Fabric: Fixing incorrect retaining policy for RCTSurfacePreseter (crash in RCTNativeAnimatedModule)
Summary: This fixing a crash in RCTNativeAnimatedModule caused by accessing an `RCTSurfacePreseter` instance as "Objective-C runtime associated object" which was retained with `OBJC_ASSOCIATION_ASSIGN` policy. The documentation for `OBJC_ASSOCIATION_ASSIGN` says "Specifies a weak reference to the associated object." but it's a lie ( https://stackoverflow.com/questions/16569840/using-objc-setassociatedobject-with-weak-references) ). The policy is actually `ASSIGN` (aka `unsafe-unretained`). That's why it's crashing. We change that to `OBJC_ASSOCIATION_RETAIN` to retain the object (which meets the expectation of the interface of the category). We also should not have over-retaining issues because: * SurfacePresenter does not retain a Bridge or any object that can retain a Bridge; * SurfacePresenter is a long-living object, we don't recreate it during bridge reloading or stuff like that. Changelog: [Internal] Fabric-specific internal change. Reviewed By: sammy-SC Differential Revision: D19333869 fbshipit-source-id: 1ff03659a880f2742b909c5668c47144719eeee2
1 parent aa0ef15 commit 5e6c61e

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed
 

‎React/Modules/RCTSurfacePresenterStub.m

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ @implementation RCTBridge (RCTSurfacePresenterStub)
1616

1717
- (void)setSurfacePresenter:(id<RCTSurfacePresenterStub>)surfacePresenter
1818
{
19-
objc_setAssociatedObject(self, @selector(surfacePresenter), surfacePresenter, OBJC_ASSOCIATION_ASSIGN);
19+
objc_setAssociatedObject(self, @selector(surfacePresenter), surfacePresenter, OBJC_ASSOCIATION_RETAIN);
2020
}
2121

2222
@end

0 commit comments

Comments
 (0)