[ReactNative] Fix RCTJavaScriptContext deallocation (attempt #2)
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
4a262e0f2b
commit
f2d65ea85b
|
@ -344,15 +344,16 @@ RCT_NOT_IMPLEMENTED(-initWithBundleURL:(__unused NSURL *)bundleURL
|
|||
RCTLatestExecutor = nil;
|
||||
}
|
||||
|
||||
void (^mainThreadInvalidate)(void) = ^{
|
||||
RCTAssertMainThread();
|
||||
|
||||
[_mainDisplayLink invalidate];
|
||||
_mainDisplayLink = nil;
|
||||
|
||||
// Invalidate modules
|
||||
dispatch_group_t group = dispatch_group_create();
|
||||
for (RCTModuleData *moduleData in _modules) {
|
||||
if (moduleData.instance == _javaScriptExecutor) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ([moduleData.instance respondsToSelector:@selector(invalidate)]) {
|
||||
[moduleData dispatchBlock:^{
|
||||
[(id<RCTInvalidating>)moduleData.instance invalidate];
|
||||
|
@ -361,36 +362,18 @@ RCT_NOT_IMPLEMENTED(-initWithBundleURL:(__unused NSURL *)bundleURL
|
|||
moduleData.queue = nil;
|
||||
}
|
||||
dispatch_group_notify(group, dispatch_get_main_queue(), ^{
|
||||
[_javaScriptExecutor executeBlockOnJavaScriptQueue:^{
|
||||
[_jsDisplayLink invalidate];
|
||||
_jsDisplayLink = nil;
|
||||
|
||||
[_javaScriptExecutor invalidate];
|
||||
_javaScriptExecutor = nil;
|
||||
}];
|
||||
|
||||
_modules = nil;
|
||||
_modulesByName = nil;
|
||||
_frameUpdateObservers = nil;
|
||||
});
|
||||
};
|
||||
|
||||
if (!_javaScriptExecutor) {
|
||||
|
||||
// No JS thread running
|
||||
mainThreadInvalidate();
|
||||
return;
|
||||
}
|
||||
|
||||
[_javaScriptExecutor executeBlockOnJavaScriptQueue:^{
|
||||
|
||||
/**
|
||||
* JS Thread deallocations
|
||||
*/
|
||||
[_javaScriptExecutor invalidate];
|
||||
_javaScriptExecutor = nil;
|
||||
|
||||
[_jsDisplayLink invalidate];
|
||||
_jsDisplayLink = nil;
|
||||
|
||||
/**
|
||||
* Main Thread deallocations
|
||||
*/
|
||||
dispatch_async(dispatch_get_main_queue(), mainThreadInvalidate);
|
||||
|
||||
}];
|
||||
}
|
||||
|
||||
#pragma mark - RCTBridge methods
|
||||
|
|
|
@ -320,6 +320,7 @@ static NSError *RCTNSErrorFromJSError(JSContextRef context, JSValueRef jsError)
|
|||
onThread:_javaScriptThread
|
||||
withObject:nil
|
||||
waitUntilDone:NO];
|
||||
_context = nil;
|
||||
}
|
||||
|
||||
- (void)dealloc
|
||||
|
|
Loading…
Reference in New Issue