Skip to content

Commit de9c421

Browse files
Mehdi Mulaniide
authored andcommitted
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
1 parent fe0ce84 commit de9c421

1 file changed

Lines changed: 4 additions & 0 deletions

File tree

React/CxxBridge/RCTCxxBridge.mm

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -917,6 +917,10 @@ - (void)invalidate
917917
self->_moduleDataByID = nil;
918918
self->_moduleClassesByID = nil;
919919
self->_pendingCalls = nil;
920+
921+
[self->_jsThread cancel];
922+
self->_jsThread = nil;
923+
CFRunLoopStop(CFRunLoopGetCurrent());
920924
}];
921925
});
922926
}

0 commit comments

Comments
 (0)