mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
9ef5107d04
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: https://github.com/facebook/react-native/pull/24745 Reviewed By: fkgozali Differential Revision: D15248848 Pulled By: hramos fbshipit-source-id: 1da835cc935dfbf4e7bb6fbf2aea29bfdc9bd6fa
29 lines
518 B
JavaScript
29 lines
518 B
JavaScript
/**
|
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*
|
|
* @flow strict
|
|
* @format
|
|
*/
|
|
|
|
'use strict';
|
|
|
|
export opaque type BlobCollector = {};
|
|
|
|
export type BlobData = {
|
|
blobId: string,
|
|
offset: number,
|
|
size: number,
|
|
name?: string,
|
|
type?: string,
|
|
lastModified?: number,
|
|
__collector?: ?BlobCollector,
|
|
};
|
|
|
|
export type BlobOptions = {
|
|
type: string,
|
|
lastModified: number,
|
|
};
|