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
This commit is contained in:
Valentin Shergin
2020-05-08 17:34:15 -07:00
committed by Facebook GitHub Bot
parent f535c8b4bb
commit aece57be29
+17
View File
@@ -241,10 +241,20 @@ struct RCTInstanceCallback : public InstanceCallback {
_moduleDataByID = [NSMutableArray new];
[RCTBridge setCurrentBridge:self];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(handleMemoryWarning)
name:UIApplicationDidReceiveMemoryWarningNotification
object:nil];
}
return self;
}
- (void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
+ (void)runRunLoop
{
@autoreleasepool {
@@ -278,6 +288,13 @@ struct RCTInstanceCallback : public InstanceCallback {
}
}
- (void)handleMemoryWarning
{
if (_reactInstance) {
_reactInstance->handleMemoryPressure(15 /* TRIM_MEMORY_RUNNING_CRITICAL */);
}
}
/**
* Ensure block is run on the JS thread. If we're already on the JS thread, the block will execute synchronously.
* If we're not on the JS thread, the block is dispatched to that thread. Any errors encountered while executing