question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:5

github_iconTop GitHub Comments

1reaction
janicduplessiscommented, May 31, 2018

Fixed in #19333

0reactions
janicduplessiscommented, May 18, 2018

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

How do I fix or work around this memory leak in fetch?
I played around a bit with it and it seems to be a bug with the handling of the response so that it...
Read more >
4 Types of Memory Leaks in JavaScript and How to Get Rid Of ...
In essence, memory leaks can be defined as memory that is not required by an application anymore that for some reason is not...
Read more >
Promise.race, fetch and avoiding memory leaks
There are a couple of ways to cancel a fetch call. The new `AbortController` API is designed specifically for this purpose.
Read more >
Eradicating Memory Leaks In Javascript - LambdaTest
A Memory leak can be defined as a piece of memory that is no longer being used or required by an application but...
Read more >
Fixing memory leaks in web applications | Read the Tea Leaves
That's all it takes to introduce a memory leak. If you call addEventListener on some global object (the window , the <body> ,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found