From c68e69cb670be224ea597cc37139ef19b0ff60d8 Mon Sep 17 00:00:00 2001 From: Valentin Shergin Date: Sun, 25 Nov 2018 22:15:00 -0800 Subject: [PATCH] Fabric: Proper handling of memory pressure event in RCTComponentViewRegistry Summary: View recycling can be pretty aggressive and memory intensive, so we can properly react on system memory-pressure notification. Reviewed By: mdvacca Differential Revision: D13176278 fbshipit-source-id: 38ea1b27da988aeaaa5db6ac0b94389a0bd2799e --- .../Fabric/Mounting/RCTComponentViewRegistry.mm | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/React/Fabric/Mounting/RCTComponentViewRegistry.mm b/React/Fabric/Mounting/RCTComponentViewRegistry.mm index c5e156390..deab9e4b5 100644 --- a/React/Fabric/Mounting/RCTComponentViewRegistry.mm +++ b/React/Fabric/Mounting/RCTComponentViewRegistry.mm @@ -81,11 +81,22 @@ const NSInteger RCTComponentViewRegistryRecyclePoolMaxSize = 1024; _recyclePool = [NSMapTable mapTableWithKeyOptions:NSPointerFunctionsOpaquePersonality | NSPointerFunctionsOpaqueMemory valueOptions:NSPointerFunctionsObjectPersonality]; _componentViewFactory = [RCTComponentViewFactory standardComponentViewFactory]; + + + [[NSNotificationCenter defaultCenter] addObserver:self + selector:@selector(handleApplicationDidReceiveMemoryWarningNotification) + name:UIApplicationDidReceiveMemoryWarningNotification + object:nil]; } return self; } +- (void)dealloc +{ + [[NSNotificationCenter defaultCenter] removeObserver:self]; +} + - (UIView *)dequeueComponentViewWithComponentHandle:(ComponentHandle)componentHandle tag:(ReactTag)tag { @@ -177,4 +188,9 @@ const NSInteger RCTComponentViewRegistryRecyclePoolMaxSize = 1024; [componentViews addObject:componentView]; } +- (void)handleApplicationDidReceiveMemoryWarningNotification +{ + [_recyclePool removeAllObjects]; +} + @end