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.

Severe memory leak affecting fetch(), iOS Release Mode 0.59.0-rc.3, 0.58.6, 0.57.8

See original GitHub issue

🐛 Bug Report

Every call to fetch() uses memory and does not release it. The larger the fetch response, the more memory leaked.

  • I’ve confirmed that this is happening in 0.57.8, 0.58.6, and 0.59.0-rc.3.
  • I’ve tried this with both node-fetch and whatwg-fetch and it happens using both libraries.
  • It is not isolated to response.blob(). It affects all types of responses.
  • It happens with both Release and Debug.
  • It happens with raw XMLHttpRequest as well as fetch.
  • I can confirm that it’s happening on a (real) iPhone X with iOS 12.1.4 and the Simulator for an iPhone 8 with iOS 12.1.

Comparing memory snapshots in Safari found no difference in size even while the Chrome/Xcode memory profiles showed dramatic increases in memory. I’m not great at debugging memory leaks so I could be wrong but I suspect that means it might be on the native side and not on the JS side.

To Reproduce

I’ve created an example repo to reproduce the error in 0.59.0-rc.3: https://github.com/cjroth/react-native-fetch-memory-leak. You can copy the App.js and see that it happens in previous versions as well.

Expected Behavior

After each fetch() call that is no longer referenced, the memory should return to what it was previously.

Code Example

https://github.com/cjroth/react-native-fetch-memory-leak

Environment

  React Native Environment Info:
    System:
      OS: macOS 10.14.1
      CPU: (4) x64 Intel(R) Core(TM) i7-4650U CPU @ 1.70GHz
      Memory: 16.96 MB / 8.00 GB
      Shell: 5.3 - /bin/zsh
    Binaries:
      Node: 11.10.0 - /usr/local/bin/node
      Yarn: 1.13.0 - /usr/local/bin/yarn
      npm: 6.8.0 - /usr/local/bin/npm
      Watchman: 4.9.0 - /usr/local/bin/watchman
    SDKs:
      iOS SDK:
        Platforms: iOS 12.1, macOS 10.14, tvOS 12.1, watchOS 5.1
    IDEs:
      Xcode: 10.1/10B61 - /usr/bin/xcodebuild
    npmPackages:
      react: 16.8.3 => 16.8.3 
      react-native: 0.59.0-rc.3 => 0.59.0-rc.3 
    npmGlobalPackages:
      react-native-cli: 2.0.1
      react-native-git-upgrade: 0.2.7
      react-native-rename: 2.4.0

screen shot 2019-03-06 at 9 22 40 pm

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:13
  • Comments:22 (2 by maintainers)

github_iconTop GitHub Comments

8reactions
timsawtellcommented, Mar 10, 2019

I think I’ve fixed it. Time to make my first PR into RN.

image

I found that the RCTNetworkTasks were not de-allocating, and that RCTBlobManager.mm was holding onto it’s blobs (NSData) forever after telling the RCTNetworking coordination code about the response.

7reactions
noahpryorcommented, Mar 8, 2019

I was able to reproduce using the iOS simulator and a variant of @cjroth s code with a five mb test file here screenshot 2019-03-07 21 12 39

Read more comments on GitHub >

github_iconTop Results From Across the Web

Severe memory leak affecting fetch(), iOS Release Mode 0.59 ...
Does anyone know if Axios uses fetch under the hood at all? I'm using fetch on one of my apps and it doesn't...
Read more >
Tracking down a memory leak | Apple Developer Forums
I've discovered that my app has a memory leak, where when I close a window, ... view controllers, and associated objects) actually doesn't...
Read more >
Solving Memory Issues: What Is A Fibernode In Chrome Dev ...
Severe memory leak affecting fetch iOS Release Mode 0.59.0rc.3 0.58.6 0.57.8 that means it might be on the native side and not on...
Read more >
Field Notice: FN - 70359 - C3650/C3850 and C9300/C9500 ...
... that run on a Cisco IOS XE Software Release as mentioned in Products Affected List might observe a memory leak in 'linux_iosd-imag'...
Read more >
What Are iOS Memory Leaks and How to Detect Them?
A memory leak is a piece of memory that was allocated at one point but never released, and is also no longer referenced...
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