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

fetch() leaks memory on each request due to unreleased Blobs #19248

Closed
3 tasks done
jesenko opened this issue May 14, 2018 · 5 comments
Closed
3 tasks done

fetch() leaks memory on each request due to unreleased Blobs #19248

jesenko opened this issue May 14, 2018 · 5 comments
Labels
Impact: Regression Describes a behavior that used to work on a prior release, but stopped working recently. Issue: Author Provided Repro This issue can be reproduced in Snack or an attached project. JavaScript 🌐Networking Related to a networking API. Resolution: Locked This issue was locked by the bot.

Comments

@jesenko
Copy link

jesenko commented May 14, 2018

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 #11573, and is thus affecting v0.54 and v0.55

@react-native-bot

This comment has been minimized.

@hramos hramos added Impact: Regression Describes a behavior that used to work on a prior release, but stopped working recently. Issue: Author Provided Repro This issue can be reproduced in Snack or an attached project. JavaScript and removed ❔Needs More Information labels May 15, 2018
@jesenko
Copy link
Author

jesenko commented May 17, 2018

Note that this issue is NOT related to usage of new blob api as the title might suggest. Memory leak occurs on all http requests. E.g. if app requests 10mb of various JSON data during it's lifetime, it will leak ~20mb of device RAM permanently.

@kelset
Copy link
Collaborator

kelset commented May 17, 2018

Oh wow nice catch! Thanks for providing the repro details

@janicduplessis
Copy link
Contributor

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. #19333

@janicduplessis
Copy link
Contributor

Fixed in #19333

@facebook facebook locked as resolved and limited conversation to collaborators May 31, 2019
@react-native-bot react-native-bot added the Resolution: Locked This issue was locked by the bot. label May 31, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Impact: Regression Describes a behavior that used to work on a prior release, but stopped working recently. Issue: Author Provided Repro This issue can be reproduced in Snack or an attached project. JavaScript 🌐Networking Related to a networking API. Resolution: Locked This issue was locked by the bot.
Projects
None yet
Development

No branches or pull requests

5 participants