fetch() leaks memory on each request due to unreleased Blobs
See original GitHub issue- I have reviewed the documentation
- I have searched existing issues
- I am using the latest React Native version
Environment
Environment: OS: macOS Sierra 10.12.6 Node: 8.9.4 Yarn: 1.6.0 npm: 5.6.0 Watchman: 4.7.0 Xcode: Xcode 8.3.3 Build version 8E3004b Android Studio: 3.1 AI-173.4720617
Packages: (wanted => installed) react: 16.3.1 => 16.3.2 react-native: ~0.55.2 => 0.55.4
Steps to Reproduce
Execute request using fetch
, e.g.
fetch('https://www.facebook.com').then(res => { // fetch saves response to blob: res._bodyBlob._data });
Expected Behavior
Blob with fetch response should be released once res
is out of scope (GC-ed).
Actual Behavior
Blobs corresponding to fetch response are never released, leading to increasing memory usage during a lifetime of application. Leaked memory is at least of the size of all responses already received.
I have created a simple project, demonstrating memory leak: https://github.com/jesenko/react-native-fetch-memory-leak
Issue was probably introduced with https://github.com/facebook/react-native/pull/11573, and is thus affecting v0.54 and v0.55
Issue Analytics
- State:
- Created 5 years ago
- Reactions:1
- Comments:5
Fixed in #19333
I also noticed the same issue today, it happens because the fetch polyfill uses blob responses if the Blob module is available. However the RN blob module does not implement automatic resource release when the Blob instance is GC’ed. I opened a PR to fork the fetch polyfill and remove it’s usage of blob responses by default. https://github.com/facebook/react-native/pull/19333