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

[Blob] Release underlying resources when JS instance in GC'ed #24745

Closed

Conversation

janicduplessis
Copy link
Contributor

#24405 try 2

Summary

Our Blob implementation was very problematic because it didn't release its underlying resource when the JS instance was dealocated. The main issue is that the fetch polyfill uses blobs by default if the module is available, which causes large memory leaks.

This fixes it by using the new jsi infra to attach a jsi::HostObject (BlobCollector) to Blob instances. This way when the Blob is collected, the BlobCollector also gets collected. Using the jsi::HostObject dtor we can schedule the cleanup of native resources. This is definitely not the ideal solution but otherwise it would require rewriting the whole module using TurboModules + jsi.

Fixes #23801, #20352, #21092

Changelog

[General] [Fixed] - [Blob] Release underlying resources when JS instance in GC'ed

Test Plan

  • Tested that creating a simple Blob instance results in resource allocation and deallocation. (new Blob(['HI']))
  • Tested that blob resources created by the fetch polyfill eventually get collected.

@facebook-github-bot facebook-github-bot added CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Contributor A React Native contributor. labels May 7, 2019
hramos referenced this pull request May 7, 2019
…ces when JS instance in GC'ed on iOS

Differential Revision:
D15237418

Original commit changeset: 00a94a54b0b1

fbshipit-source-id: bb6c7aa3f5b6ae7f40965b96f1e0fd8eb7512015
Copy link
Contributor

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@hramos
Copy link
Contributor

hramos commented May 7, 2019

The error still occurs, but our current understanding is that this is specific to one of our internal Buck tests, and that we'll need to update our Buck definition, something that you won't be able to change as part of this PR.

Please hold off on adding any commits to this PR. I'll work on making the necessary changes over the internal version of this PR (where I can update filepaths outside of the React Native GitHub directory) and once the issue is resolved and the internal diff lands, this PR shall be marked as merged.

@janicduplessis
Copy link
Contributor Author

Awesome! Thanks @hramos

@hramos
Copy link
Contributor

hramos commented May 8, 2019

I have a potential fix waiting for review, shouldn't be long.

@janicduplessis
Copy link
Contributor Author

@hramos There's a conflict because of 0ee5f68, let me know if you need me to do anything.

@hramos
Copy link
Contributor

hramos commented May 8, 2019

The fix I sent last night was approved this morning. The conflict did hold the initial attempt to land this back, but I just resolved it internally and kicked off another land attempt.

Copy link
Contributor

@hramos hramos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Landing.

@react-native-bot
Copy link
Collaborator

This pull request was successfully merged by @janicduplessis in 9ef5107.

When will my fix make it into a release? | Upcoming Releases

@react-native-bot react-native-bot added the Merged This PR has been merged. label May 8, 2019
pull bot pushed a commit to senseobservationsystems/react-native that referenced this pull request May 31, 2019
…cebook#24767)

Summary:
Android followup for facebook#24745. This adds a jsi object that removes blobs when it is gc'ed. We don't have many modules with native code on Android so I've added the native code directly in the blob package as a separate .so. I used a similar structure as the turbomodule package.

## Changelog

[Android] [Fixed] - [Blob] Release underlying resources when JS instance is GC'ed on Android
Pull Request resolved: facebook#24767

Differential Revision: D15279651

Pulled By: cpojer

fbshipit-source-id: 2bbdc4bbcbeae8945588ac5e3e895c49e6ac9e1a
M-i-k-e-l pushed a commit to M-i-k-e-l/react-native that referenced this pull request Mar 10, 2020
…cebook#24767)

Summary:
Android followup for facebook#24745. This adds a jsi object that removes blobs when it is gc'ed. We don't have many modules with native code on Android so I've added the native code directly in the blob package as a separate .so. I used a similar structure as the turbomodule package.

## Changelog

[Android] [Fixed] - [Blob] Release underlying resources when JS instance is GC'ed on Android
Pull Request resolved: facebook#24767

Differential Revision: D15279651

Pulled By: cpojer

fbshipit-source-id: 2bbdc4bbcbeae8945588ac5e3e895c49e6ac9e1a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Contributor A React Native contributor. Merged This PR has been merged.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

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