Fix JSGlobalContext leak

Reviewed By: javache

Differential Revision: D4299616

fbshipit-source-id: f30e88fbdd08422f1d0ae3c10b8a9af13d637135
This commit is contained in:
Alexey Lang 2016-12-12 05:38:50 -08:00 committed by Facebook Github Bot
parent 4252ac75ea
commit 66c5305fa8
1 changed files with 3 additions and 0 deletions

View File

@ -342,6 +342,9 @@ static NSThread *newJavaScriptThread(void)
}
contextRef = JSC_JSGlobalContextCreateInGroup(self->_useCustomJSCLibrary, nullptr, nullptr);
context = [JSC_JSContext(contextRef) contextWithJSGlobalContextRef:contextRef];
// We release the global context reference here to balance retainCount after JSGlobalContextCreateInGroup.
// The global context _is not_ going to be released since the JSContext keeps the strong reference to it.
JSC_JSGlobalContextRelease(contextRef);
self->_context = [[RCTJavaScriptContext alloc] initWithJSContext:context onThread:self->_javaScriptThread];
[[NSNotificationCenter defaultCenter] postNotificationName:RCTJavaScriptContextCreatedNotification
object:context];