react-native icon indicating copy to clipboard operation
react-native copied to clipboard

fix fetch memory leak

Open huzhanbo1996 opened this issue 1 year ago • 4 comments

Summary:

Root cause of the fetch memory leak:

The fetch requests store its result inside Blob which memory is managed by BlobCollector. On the JS engine side, the Blob is represented by an ID as JS string, and the GC don't know the size of the blob. So GC won't have interests to release the Blob.

Fix:

On iOS and Android, use setExternalMemoryPressure to acknowledge JS engine the size of Blob it holds.

Changelog:

[GENERAL] [FIXED] - fix fetch memory leak

Test Plan:

RepeatedlyFetch inside XHR example

huzhanbo1996 avatar Apr 30 '24 15:04 huzhanbo1996

This PR addresses issues #39100 #43647. @cortinico PTAL

huzhanbo1996 avatar Apr 30 '24 15:04 huzhanbo1996

Platform Engine Arch Size (bytes) Diff
android hermes arm64-v8a 19,478,635 +91
android hermes armeabi-v7a n/a --
android hermes x86 n/a --
android hermes x86_64 n/a --
android jsc arm64-v8a 22,851,235 +148
android jsc armeabi-v7a n/a --
android jsc x86 n/a --
android jsc x86_64 n/a --

Base commit: 0383669a4b19289678ed75b28e38a74fabb01a64 Branch: main

analysis-bot avatar Apr 30 '24 16:04 analysis-bot

@Sunbreak @NickGerleman @cortinico PTAL

huzhanbo1996 avatar May 08 '24 13:05 huzhanbo1996

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

facebook-github-bot avatar May 09 '24 05:05 facebook-github-bot

Hi @NickGerleman, some facebook internal Lint/Check failed. Could you give me some guide to fix them?

huzhanbo1996 avatar May 09 '24 16:05 huzhanbo1996

@NickGerleman merged this pull request in facebook/react-native@c647950e5e78f1bcd110111067b21daa44e4d464.

facebook-github-bot avatar May 10 '24 03:05 facebook-github-bot

This pull request was successfully merged by huzhanbo.luc in c647950e5e78f1bcd110111067b21daa44e4d464.

When will my fix make it into a release? | How to file a pick request?

github-actions[bot] avatar May 10 '24 03:05 github-actions[bot]

nice, waiting for this improvement!

see2ever avatar May 10 '24 05:05 see2ever

how about using libs fetching api like axios ?

chanphiromsok avatar May 15 '24 14:05 chanphiromsok