Skip to content

Commit c68e69c

Browse files
sherginfacebook-github-bot
authored andcommitted
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
1 parent cd5f0bd commit c68e69c

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

React/Fabric/Mounting/RCTComponentViewRegistry.mm

+16
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,22 @@ - (instancetype)init
8181
_recyclePool = [NSMapTable mapTableWithKeyOptions:NSPointerFunctionsOpaquePersonality | NSPointerFunctionsOpaqueMemory
8282
valueOptions:NSPointerFunctionsObjectPersonality];
8383
_componentViewFactory = [RCTComponentViewFactory standardComponentViewFactory];
84+
85+
86+
[[NSNotificationCenter defaultCenter] addObserver:self
87+
selector:@selector(handleApplicationDidReceiveMemoryWarningNotification)
88+
name:UIApplicationDidReceiveMemoryWarningNotification
89+
object:nil];
8490
}
8591

8692
return self;
8793
}
8894

95+
- (void)dealloc
96+
{
97+
[[NSNotificationCenter defaultCenter] removeObserver:self];
98+
}
99+
89100
- (UIView<RCTComponentViewProtocol> *)dequeueComponentViewWithComponentHandle:(ComponentHandle)componentHandle
90101
tag:(ReactTag)tag
91102
{
@@ -177,4 +188,9 @@ - (void)_enqueueComponentViewWithComponentHandle:(ComponentHandle)componentHandl
177188
[componentViews addObject:componentView];
178189
}
179190

191+
- (void)handleApplicationDidReceiveMemoryWarningNotification
192+
{
193+
[_recyclePool removeAllObjects];
194+
}
195+
180196
@end

0 commit comments

Comments
 (0)