Skip to content

Commit 948cbfd

Browse files
zhongwuzwfacebook-github-bot
authored andcommitted
Add autorelease pool for each run loop for JS Thread (#27395)
Summary: Fixes #27327 , we need to create autorelease pool for each run loop in secondary thread, otherwise application may have memory issues. More details can refer to [CreatingThreads](https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/Multithreading/CreatingThreads/CreatingThreads.html) ![image](https://user-images.githubusercontent.com/5061845/70033738-05fa2980-15eb-11ea-9adb-f01bee937766.png) ## Changelog [iOS] [Fixed] - Add autorelease pool for each run loop for JS Thread Pull Request resolved: #27395 Test Plan: Example can be found in #27327. No memory spikes any more. Reviewed By: PeteTheHeat Differential Revision: D19132504 Pulled By: fkgozali fbshipit-source-id: d1747f27d36e9a7934966b34aa46d344e06193b3
1 parent eb95b2f commit 948cbfd

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

React/CxxBridge/RCTMessageThread.mm

+6-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,12 @@
3636

3737
// This is analogous to dispatch_async
3838
void RCTMessageThread::runAsync(std::function<void()> func) {
39-
CFRunLoopPerformBlock(m_cfRunLoop, kCFRunLoopCommonModes, ^{ func(); });
39+
CFRunLoopPerformBlock(m_cfRunLoop, kCFRunLoopCommonModes, ^{
40+
// Create an autorelease pool each run loop to prevent memory footprint from growing too large, which can lead to performance problems.
41+
@autoreleasepool {
42+
func();
43+
}
44+
});
4045
CFRunLoopWakeUp(m_cfRunLoop);
4146
}
4247

0 commit comments

Comments
 (0)