-
Notifications
You must be signed in to change notification settings - Fork 24.4k
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
Fetching specific JSON causes massive memory leak #20352
Comments
There are two issues going on here, in my judgement:
|
Unfortunately, no. I just updated the test repo to 0.57 and the issue is still occurring. After downloading the tiny JSON file once a second for sixty seconds (and not disposing of the result), memory usage of the Release build of the test project climbs to over 2 GiB. |
We're also experiencing the huge memory allocation when fetching JSON. We're fetching a much bigger resource than the example provided here, and I wonder if the memory allocation is proportional because our app gets killed by iOS for memory consumption (spike from 150mb to over 700mb), even before the fetch call completes. |
I’ve been able to get around this issue by immediately cloning the JSON response after receiving it. |
i get a similar problem. i fetch a 15mo Json file. often the app get killed or get stuck in loading it.
|
Seems memory is fine in Release mode but bad in debug mode. |
Yes, in our case the memory consumption graph looks extremely different in debug mode compared to release. |
Could it be related to this ? |
@gablorquet Looking at the reproduction code, it doesn't look like NetInfo is involved. |
Does this repro on 0.59? Also, it isn't clear from the issue if this is iOS or Android. If it is Android I could imagine that this might be fixed by the latest JSC. |
@TheSavior Yes, I confirmed on iOS, it has leaks, I checked both iOS and Android implementations, they share the same handle logic, so I assume Android may also has this issue. One leak we find is blob not removed, besides this, seems still has other leaks. @TheSavior Oh, sorry, I messed up #23801 and this one, the comment above is based on #23801 .But I think this also has that problem. |
If I recall correctly, this issue is iOS-only. My bad on not making that clear initially. The repro I made above is iOS-only. I have updated the repro repo to RN 0.59.1 and unfortunately the issue remains. |
Got it. Thanks for giving it a try. Do you have any sense on whether this is the same problem as #23801? If so, as there is more conversation happening there than I'd like to close this as a duplicate. |
Hmm... I took a quick look at the code to the repro in #23801, and on first glance I think they are different. But it's very possible they are caused by some of the same underlying issues. Pulling from my comment above:
The first issue doesn't seem to apply in #23801, as the size of their downloaded file is pretty substantial (5 MiB) in contrast with the tiny file here (<1 KiB). The second issue doesn't seem to apply either. In the repro for #23801, the author actually never keeps anything from the network request around, whereas I was only able to demonstrate my "massive" memory leak by keeping the resultant JSON blob and appending it to an array. My issue goes away if I simply clone the JSON blob and keep that instead of keeping what It appears that there are two distinct memory leak issues: one that none of the native resources for the network request are cleaned up unless the resultant JS resources are garbage-collected, and the other that some of the native resources aren't cleaned up even if JS resources are never allocated. |
@Ashoat, Have you solved this problem? Do you have any solution for this. |
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 [General] [Fixed] - [Blob] Release underlying resources when JS instance in GC'ed Pull Request resolved: #24405 Differential Revision: D15237418 Pulled By: cpojer fbshipit-source-id: 00a94a54b0b172fbc62324364b753d192ac7016a
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 [General] [Fixed] - [Blob] Release underlying resources when JS instance in GC'ed Pull Request resolved: #24745 Reviewed By: fkgozali Differential Revision: D15248848 Pulled By: hramos fbshipit-source-id: 1da835cc935dfbf4e7bb6fbf2aea29bfdc9bd6fa
Fixed in 9ef5107 for ios and I just opened a pr with a fix for android. |
Should this be re-opened? It's still an issue and as far as I understand the PR was pulled |
I can't find evidence that the PR was pulled, but if you could demonstrate that the issue is still extant in 0.60 (which should include the PR) I think it would make sense to reopen. I can't seem to get |
The fix on android is working for us with 0.61.5 (and presumably some earlier versions too, though we've not tried them). Only for the default JavaScriptCore/jsc engine though, not hermes or v8 (see the above two issues). |
Environment
Description
Downloading this <1 KiB JSON file once a second, parsing the JSON, and appending the resultant JSON to an array, causes the demo app below to hit 500MiB of memory usage in less than 15 seconds. Each request permanently allocates ~35MiB of memory.
Reproducible Demo
I have created a repo to reproduce the issue.
The text was updated successfully, but these errors were encountered: