Skip to content

Commit

Permalink
Add autorelease pool for each run loop for JS Thread (#27395)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
zhongwuzw authored and facebook-github-bot committed Dec 17, 2019
1 parent eb95b2f commit 948cbfd
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion React/CxxBridge/RCTMessageThread.mm
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,12 @@

// 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);
}

Expand Down

0 comments on commit 948cbfd

Please sign in to comment.