Skip to content

Commit

Permalink
Fabric: Calling JSVM GC on memory pressure event on iOS
Browse files Browse the repository at this point in the history
Summary:
This change is especially important for Fabric when a lot of objects (mostly `ShadowNode`s) have shared ownership. Without this change, JSVM could not know that bunch of natively allocated objects should be deallocated.

Changelog: [Internal] Fabric-specific internal change.

Reviewed By: dulinriley

Differential Revision: D21484773

fbshipit-source-id: 46e32de0f108082e60df346884c9287023156149
  • Loading branch information
shergin authored and facebook-github-bot committed May 9, 2020
1 parent f535c8b commit aece57b
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions React/CxxBridge/RCTCxxBridge.mm
Original file line number Diff line number Diff line change
Expand Up @@ -241,10 +241,20 @@ - (instancetype)initWithParentBridge:(RCTBridge *)bridge
_moduleDataByID = [NSMutableArray new];

[RCTBridge setCurrentBridge:self];

[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(handleMemoryWarning)
name:UIApplicationDidReceiveMemoryWarningNotification
object:nil];
}
return self;
}

- (void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
}

+ (void)runRunLoop
{
@autoreleasepool {
Expand Down Expand Up @@ -278,6 +288,13 @@ - (void)_tryAndHandleError:(dispatch_block_t)block
}
}

- (void)handleMemoryWarning
{
if (_reactInstance) {
_reactInstance->handleMemoryPressure(15 /* TRIM_MEMORY_RUNNING_CRITICAL */);
}
}

/**
* Ensure block is run on the JS thread. If we're already on the JS thread, the block will execute synchronously.
* If we're not on the JS thread, the block is dispatched to that thread. Any errors encountered while executing
Expand Down

0 comments on commit aece57b

Please sign in to comment.