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
This commit is contained in:
Valentin Shergin 2018-11-25 22:15:00 -08:00 committed by Facebook Github Bot
parent cd5f0bd95c
commit c68e69cb67
1 changed files with 16 additions and 0 deletions

View File

@ -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<RCTComponentViewProtocol> *)dequeueComponentViewWithComponentHandle:(ComponentHandle)componentHandle
tag:(ReactTag)tag
{
@ -177,4 +188,9 @@ const NSInteger RCTComponentViewRegistryRecyclePoolMaxSize = 1024;
[componentViews addObject:componentView];
}
- (void)handleApplicationDidReceiveMemoryWarningNotification
{
[_recyclePool removeAllObjects];
}
@end