Skip to content

Commit aece57b

Browse files
sherginfacebook-github-bot
authored andcommitted
Fabric: Calling JSVM GC on memory pressure event on iOS
Summary: This change is especially important for Fabric when a lot of objects (mostly `ShadowNode`s) have shared ownership. Without this change, JSVM could not know that bunch of natively allocated objects should be deallocated. Changelog: [Internal] Fabric-specific internal change. Reviewed By: dulinriley Differential Revision: D21484773 fbshipit-source-id: 46e32de0f108082e60df346884c9287023156149
1 parent f535c8b commit aece57b

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

React/CxxBridge/RCTCxxBridge.mm

+17
Original file line numberDiff line numberDiff line change
@@ -241,10 +241,20 @@ - (instancetype)initWithParentBridge:(RCTBridge *)bridge
241241
_moduleDataByID = [NSMutableArray new];
242242

243243
[RCTBridge setCurrentBridge:self];
244+
245+
[[NSNotificationCenter defaultCenter] addObserver:self
246+
selector:@selector(handleMemoryWarning)
247+
name:UIApplicationDidReceiveMemoryWarningNotification
248+
object:nil];
244249
}
245250
return self;
246251
}
247252

253+
- (void)dealloc
254+
{
255+
[[NSNotificationCenter defaultCenter] removeObserver:self];
256+
}
257+
248258
+ (void)runRunLoop
249259
{
250260
@autoreleasepool {
@@ -278,6 +288,13 @@ - (void)_tryAndHandleError:(dispatch_block_t)block
278288
}
279289
}
280290

291+
- (void)handleMemoryWarning
292+
{
293+
if (_reactInstance) {
294+
_reactInstance->handleMemoryPressure(15 /* TRIM_MEMORY_RUNNING_CRITICAL */);
295+
}
296+
}
297+
281298
/**
282299
* Ensure block is run on the JS thread. If we're already on the JS thread, the block will execute synchronously.
283300
* If we're not on the JS thread, the block is dispatched to that thread. Any errors encountered while executing

0 commit comments

Comments
 (0)