[ReactNative] Fix RCTJavaScriptContext deallocation
Summary: The context wasn't being explicitly released before, since it'd be immediately released. Now that the executors are bridge modules, it was only being deallocated when the modules were released, what caused the threads to not be released at all.
This commit is contained in:
parent
bb141e3a3c
commit
a251316a5f
|
@ -347,53 +347,36 @@ RCT_NOT_IMPLEMENTED(-initWithBundleURL:(__unused NSURL *)bundleURL
|
||||||
RCTLatestExecutor = nil;
|
RCTLatestExecutor = nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
void (^mainThreadInvalidate)(void) = ^{
|
[_mainDisplayLink invalidate];
|
||||||
RCTAssertMainThread();
|
_mainDisplayLink = nil;
|
||||||
|
|
||||||
[_mainDisplayLink invalidate];
|
// Invalidate modules
|
||||||
_mainDisplayLink = nil;
|
dispatch_group_t group = dispatch_group_create();
|
||||||
|
for (RCTModuleData *moduleData in _modules) {
|
||||||
// Invalidate modules
|
if (moduleData.instance == _javaScriptExecutor) {
|
||||||
dispatch_group_t group = dispatch_group_create();
|
continue;
|
||||||
for (RCTModuleData *moduleData in _modules) {
|
|
||||||
if ([moduleData.instance respondsToSelector:@selector(invalidate)]) {
|
|
||||||
[moduleData dispatchBlock:^{
|
|
||||||
[(id<RCTInvalidating>)moduleData.instance invalidate];
|
|
||||||
} dispatchGroup:group];
|
|
||||||
}
|
|
||||||
moduleData.queue = nil;
|
|
||||||
}
|
}
|
||||||
dispatch_group_notify(group, dispatch_get_main_queue(), ^{
|
|
||||||
_modules = nil;
|
|
||||||
_modulesByName = nil;
|
|
||||||
_frameUpdateObservers = nil;
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
if (!_javaScriptExecutor) {
|
if ([moduleData.instance respondsToSelector:@selector(invalidate)]) {
|
||||||
|
[moduleData dispatchBlock:^{
|
||||||
// No JS thread running
|
[(id<RCTInvalidating>)moduleData.instance invalidate];
|
||||||
mainThreadInvalidate();
|
} dispatchGroup:group];
|
||||||
return;
|
}
|
||||||
|
moduleData.queue = nil;
|
||||||
}
|
}
|
||||||
|
dispatch_group_notify(group, dispatch_get_main_queue(), ^{
|
||||||
|
[_javaScriptExecutor executeBlockOnJavaScriptQueue:^{
|
||||||
|
[_jsDisplayLink invalidate];
|
||||||
|
_jsDisplayLink = nil;
|
||||||
|
|
||||||
[_javaScriptExecutor executeBlockOnJavaScriptQueue:^{
|
[_javaScriptExecutor invalidate];
|
||||||
|
_javaScriptExecutor = nil;
|
||||||
|
}];
|
||||||
|
|
||||||
/**
|
_modules = nil;
|
||||||
* JS Thread deallocations
|
_modulesByName = nil;
|
||||||
*/
|
_frameUpdateObservers = nil;
|
||||||
[_javaScriptExecutor invalidate];
|
});
|
||||||
_javaScriptExecutor = nil;
|
|
||||||
|
|
||||||
[_jsDisplayLink invalidate];
|
|
||||||
_jsDisplayLink = nil;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Main Thread deallocations
|
|
||||||
*/
|
|
||||||
dispatch_async(dispatch_get_main_queue(), mainThreadInvalidate);
|
|
||||||
|
|
||||||
}];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#pragma mark - RCTBridge methods
|
#pragma mark - RCTBridge methods
|
||||||
|
|
|
@ -320,6 +320,7 @@ static NSError *RCTNSErrorFromJSError(JSContextRef context, JSValueRef jsError)
|
||||||
onThread:_javaScriptThread
|
onThread:_javaScriptThread
|
||||||
withObject:nil
|
withObject:nil
|
||||||
waitUntilDone:NO];
|
waitUntilDone:NO];
|
||||||
|
_context = nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)dealloc
|
- (void)dealloc
|
||||||
|
|
Loading…
Reference in New Issue