From 66c5305fa8b71ef085689f3f6a489d7fe58cec95 Mon Sep 17 00:00:00 2001 From: Alexey Lang Date: Mon, 12 Dec 2016 05:38:50 -0800 Subject: [PATCH] Fix JSGlobalContext leak Reviewed By: javache Differential Revision: D4299616 fbshipit-source-id: f30e88fbdd08422f1d0ae3c10b8a9af13d637135 --- React/Executors/RCTJSCExecutor.mm | 3 +++ 1 file changed, 3 insertions(+) diff --git a/React/Executors/RCTJSCExecutor.mm b/React/Executors/RCTJSCExecutor.mm index 3bad2ee2d..66ad2ef83 100644 --- a/React/Executors/RCTJSCExecutor.mm +++ b/React/Executors/RCTJSCExecutor.mm @@ -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];