From 96ecad43418fecc684f427ed098fc9565550bf3c Mon Sep 17 00:00:00 2001 From: Samuel Susla Date: Fri, 30 Oct 2020 08:16:58 -0700 Subject: [PATCH] Trigger garbage collection when the app receive memory warning Summary: Changelog: [internal] The condition inside `[RCTCxxBridge handleMemoryWarning]` was preventing JS VM from handling memory pressure if React Native was loading. This seems incorrect as loading only occurs once at the startup but memory pressure event occurs mostly after React Native was initialised. Therefore, JS VM wasn't handling memory pressure events. Reviewed By: shergin Differential Revision: D24646724 fbshipit-source-id: 7b4420fe675261e434c3427c8ad366ba0086a453 --- React/CxxBridge/RCTCxxBridge.mm | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/React/CxxBridge/RCTCxxBridge.mm b/React/CxxBridge/RCTCxxBridge.mm index e459e452ff6..3c205b906b7 100644 --- a/React/CxxBridge/RCTCxxBridge.mm +++ b/React/CxxBridge/RCTCxxBridge.mm @@ -310,7 +310,9 @@ struct RCTInstanceCallback : public InstanceCallback { - (void)handleMemoryWarning { - if (!_valid || !_loading) { + // We only want to run garbage collector when the loading is finished + // and the instance is valid. + if (!_valid || _loading) { return; }