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