mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Add autorelease pool for each run loop for JS Thread (#27395)
Summary: Fixes https://github.com/facebook/react-native/issues/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)  ## Changelog [iOS] [Fixed] - Add autorelease pool for each run loop for JS Thread Pull Request resolved: https://github.com/facebook/react-native/pull/27395 Test Plan: Example can be found in https://github.com/facebook/react-native/issues/27327. No memory spikes any more. Reviewed By: PeteTheHeat Differential Revision: D19132504 Pulled By: fkgozali fbshipit-source-id: d1747f27d36e9a7934966b34aa46d344e06193b3
This commit is contained in:
committed by
Facebook Github Bot
parent
eb95b2f855
commit
948cbfdacc
@@ -36,7 +36,12 @@ RCTMessageThread::~RCTMessageThread() {
|
||||
|
||||
// This is analogous to dispatch_async
|
||||
void RCTMessageThread::runAsync(std::function<void()> func) {
|
||||
CFRunLoopPerformBlock(m_cfRunLoop, kCFRunLoopCommonModes, ^{ func(); });
|
||||
CFRunLoopPerformBlock(m_cfRunLoop, kCFRunLoopCommonModes, ^{
|
||||
// Create an autorelease pool each run loop to prevent memory footprint from growing too large, which can lead to performance problems.
|
||||
@autoreleasepool {
|
||||
func();
|
||||
}
|
||||
});
|
||||
CFRunLoopWakeUp(m_cfRunLoop);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user