Skip to content

Commit

Permalink
Fabric: Proper handling of memory pressure event in RCTComponentViewR…
Browse files Browse the repository at this point in the history
…egistry

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
  • Loading branch information
shergin authored and facebook-github-bot committed Nov 26, 2018
1 parent cd5f0bd commit c68e69c
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions React/Fabric/Mounting/RCTComponentViewRegistry.mm
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,22 @@ - (instancetype)init
_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
{
Expand Down Expand Up @@ -177,4 +188,9 @@ - (void)_enqueueComponentViewWithComponentHandle:(ComponentHandle)componentHandl
[componentViews addObject:componentView];
}

- (void)handleApplicationDidReceiveMemoryWarningNotification
{
[_recyclePool removeAllObjects];
}

@end

0 comments on commit c68e69c

Please sign in to comment.