Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for UIApplicationDidReceiveMemoryWarningNotification not being obeyed on iOS #37973

Closed

Conversation

liamjones
Copy link
Contributor

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:

reactInstance->handleMemoryPressure(15 /* TRIM_MEMORY_RUNNING_CRITICAL */);

(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

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

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Jun 20, 2023
@facebook-github-bot
Copy link
Contributor

@sammy-SC has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@javache
Copy link
Member

javache commented Jun 20, 2023

Thanks for the fix! I'm surprised this actually was causing issues, since BOOL (and bool) are actually defined as char and are perfectly capable of representing 15

@liamjones
Copy link
Contributor Author

I'm surprised this actually was causing issues, since BOOL (and bool) are actually defined as char and are perfectly capable of representing 15

Yeah, I was confused by that too. I only picked up on it when trying to debug a memory usage issue and saw the "unrecognized pressure level" message in the console. 🤷

@analysis-bot
Copy link

Platform Engine Arch Size (bytes) Diff
android hermes arm64-v8a 9,014,611 +1
android hermes armeabi-v7a 8,275,839 +1
android hermes x86 9,528,325 -1
android hermes x86_64 9,370,718 -1
android jsc arm64-v8a 9,575,959 -1
android jsc armeabi-v7a 8,714,501 +0
android jsc x86 9,660,535 -2
android jsc x86_64 9,907,034 +0

Base commit: 6e1210e
Branch: main

@facebook-github-bot facebook-github-bot added the Merged This PR has been merged. label Jun 21, 2023
@facebook-github-bot
Copy link
Contributor

@sammy-SC merged this pull request in 8f072b4.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Merged This PR has been merged.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants