Skip to content

Commit

Permalink
Fix for UIApplicationDidReceiveMemoryWarningNotification not being ob…
Browse files Browse the repository at this point in the history
…eyed on iOS (#37973)

Summary:
Prior to 0.69, an RN app receiving the `UIApplicationDidReceiveMemoryWarningNotification` notification resulted in RN performing a GC on the JSC. Since 0.69 this has not worked, this PR fixes the issue.

Before 0.69 this was handled via a hardcoded memory pressure level: https://github.com/facebook/react-native/blob/c5c17985dae402725abb8a3a94ccedc515428711/React/CxxBridge/RCTCxxBridge.mm#L362

(It seems like the levels are an Android concept - see https://developer.android.com/reference/android/content/ComponentCallbacks2#constants_1)

In commit 0916df9 it was changed to run from a constant which could be reconfigured but a mistake (return type of `BOOL` rather than `int`) was resulting in the intended default memory pressure level of 15 (same as the old hardcoded value) being changed to 1 when it was passed on to `handleMemoryPressure`.

## Changelog:

[IOS] [FIXED] - UIApplicationDidReceiveMemoryWarningNotification has not been obeyed on iOS since RN 0.69

Pull Request resolved: #37973

Test Plan:
Tested manually via the Simulator using Debug -> Simulate Memory Warning and monitoring the console output of the app.

Before fix:

```
WARNING: Logging before InitGoogleLogging() is written to STDERR
W0620 11:21:42.824463 257294336 JSIExecutor.cpp:377] Memory warning (pressure level: 1) received by JS VM, unrecognized pressure level
```

With fix (and also the same output for the latest 0.68 tag in the repo):

```
WARNING: Logging before InitGoogleLogging() is written to STDERR
I0620 11:25:47.479444 79212544 JSIExecutor.cpp:370] Memory warning (pressure level: TRIM_MEMORY_RUNNING_CRITICAL) received by JS VM, running a GC
```

Reviewed By: javache

Differential Revision: D46857205

Pulled By: sammy-SC

fbshipit-source-id: 35121e6c4186fded6ef3ba728d9aafbc936627bb
  • Loading branch information
liamjones authored and facebook-github-bot committed Jun 21, 2023
1 parent c16e993 commit 8f072b4
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion packages/react-native/React/Base/RCTConstants.h
Original file line number Diff line number Diff line change
@@ -73,7 +73,7 @@ RCT_EXTERN void RCTSetValidateCanSendEventInRCTEventEmitter(BOOL value);
/*
* Memory Pressure Unloading Level
*/
RCT_EXTERN BOOL RCTGetMemoryPressureUnloadLevel(void);
RCT_EXTERN int RCTGetMemoryPressureUnloadLevel(void);
RCT_EXTERN void RCTSetMemoryPressureUnloadLevel(int value);

/*
2 changes: 1 addition & 1 deletion packages/react-native/React/Base/RCTConstants.m
Original file line number Diff line number Diff line change
@@ -56,7 +56,7 @@ void RCTSetValidateCanSendEventInRCTEventEmitter(BOOL value)
*/
static int RCTMemoryPressureUnloadLevel = 15;

BOOL RCTGetMemoryPressureUnloadLevel(void)
int RCTGetMemoryPressureUnloadLevel(void)
{
return RCTMemoryPressureUnloadLevel;
}

0 comments on commit 8f072b4

Please sign in to comment.