From 1f9fc0ee3a2964b067f0848e35603475e510067c Mon Sep 17 00:00:00 2001 From: Mehdi Mulani Date: Wed, 30 Aug 2017 09:37:54 -0700 Subject: [PATCH] Stop CxxBridge run loop when bridge is invalidated Summary: This fixes the `testModulesAreDeallocated` test. It was sometimes failing because the bridge's module was still alive. I debugged with the Xcode memory graph and found that the bridge was actually kept alive by a pointer from the NSThread. By killing the runloop on the thread, the thread will eventually die and thus free the bridge. One thing I didn't investigate was whether the thread was alive because of it receiving actual messages or just because the run loop was spinning. Reviewed By: javache Differential Revision: D5729925 fbshipit-source-id: 304f526129d2c5e137bfd791a6f957f6169b783e --- React/CxxBridge/RCTCxxBridge.mm | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/React/CxxBridge/RCTCxxBridge.mm b/React/CxxBridge/RCTCxxBridge.mm index cdb698f62..5883b7173 100644 --- a/React/CxxBridge/RCTCxxBridge.mm +++ b/React/CxxBridge/RCTCxxBridge.mm @@ -962,6 +962,10 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithBundleURL:(__unused NSURL *)bundleUR self->_moduleDataByID = nil; self->_moduleClassesByID = nil; self->_pendingCalls = nil; + + [self->_jsThread cancel]; + self->_jsThread = nil; + CFRunLoopStop(CFRunLoopGetCurrent()); }]; }); }