Skip to content

Commit

Permalink
Revert D15237418: [react-native][PR] [Blob] Release underlying resour…
Browse files Browse the repository at this point in the history
…ces when JS instance in GC'ed on iOS

Differential Revision:
D15237418

Original commit changeset: 00a94a54b0b1

fbshipit-source-id: bb6c7aa3f5b6ae7f40965b96f1e0fd8eb7512015
  • Loading branch information
zeyadsalloum authored and facebook-github-bot committed May 7, 2019
1 parent fdd8fad commit 05baf62
Show file tree
Hide file tree
Showing 6 changed files with 2 additions and 130 deletions.
30 changes: 2 additions & 28 deletions Libraries/Blob/BlobManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const Blob = require('Blob');
const BlobRegistry = require('BlobRegistry');
const {BlobModule} = require('NativeModules');

import type {BlobData, BlobOptions, BlobCollector} from 'BlobTypes';
import type {BlobData, BlobOptions} from 'BlobTypes';

/*eslint-disable no-bitwise */
/*eslint-disable eqeqeq */
Expand All @@ -31,21 +31,6 @@ function uuidv4(): string {
});
}

// **Temporary workaround**
// TODO(#24654): Use turbomodules for the Blob module.
// Blob collector is a jsi::HostObject that is used by native to know
// when the a Blob instance is deallocated. This allows to free the
// underlying native resources. This is a hack to workaround the fact
// that the current bridge infra doesn't allow to track js objects
// deallocation. Ideally the whole Blob object should be a jsi::HostObject.
function createBlobCollector(blobId: string): BlobCollector | null {
if (global.__blobCollectorProvider == null) {
return null;
} else {
return global.__blobCollectorProvider(blobId);
}
}

/**
* Module to manage blobs. Wrapper around the native blob module.
*/
Expand Down Expand Up @@ -109,18 +94,7 @@ class BlobManager {
*/
static createFromOptions(options: BlobData): Blob {
BlobRegistry.register(options.blobId);
return Object.assign(Object.create(Blob.prototype), {
data:
// Reuse the collector instance when creating from an existing blob.
// This will make sure that the underlying resource is only deallocated
// when all blobs that refer to it are deallocated.
options.__collector == null
? {
...options,
__collector: createBlobCollector(options.blobId),
}
: options,
});
return Object.assign(Object.create(Blob.prototype), {data: options});
}

/**
Expand Down
3 changes: 0 additions & 3 deletions Libraries/Blob/BlobTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,13 @@

'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 = {
Expand Down
13 changes: 0 additions & 13 deletions Libraries/Blob/RCTBlob.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@
objects = {

/* Begin PBXBuildFile section */
1946172A225F085900E4E008 /* RCTBlobCollector.h in Headers */ = {isa = PBXBuildFile; fileRef = 19461728225F085900E4E008 /* RCTBlobCollector.h */; };
1946172B225F085900E4E008 /* RCTBlobCollector.h in Headers */ = {isa = PBXBuildFile; fileRef = 19461728225F085900E4E008 /* RCTBlobCollector.h */; };
1946172C225F085900E4E008 /* RCTBlobCollector.mm in Sources */ = {isa = PBXBuildFile; fileRef = 19461729225F085900E4E008 /* RCTBlobCollector.mm */; };
1946172D225F085900E4E008 /* RCTBlobCollector.mm in Sources */ = {isa = PBXBuildFile; fileRef = 19461729225F085900E4E008 /* RCTBlobCollector.mm */; };
19BA88FE1F84391700741C5A /* RCTFileReaderModule.h in Copy Headers */ = {isa = PBXBuildFile; fileRef = ADDFBA6A1F33455F0064C998 /* RCTFileReaderModule.h */; };
19BA88FF1F84392900741C5A /* RCTFileReaderModule.h in Headers */ = {isa = PBXBuildFile; fileRef = ADDFBA6A1F33455F0064C998 /* RCTFileReaderModule.h */; };
19BA89001F84392F00741C5A /* RCTFileReaderModule.h in Copy Headers */ = {isa = PBXBuildFile; fileRef = ADDFBA6A1F33455F0064C998 /* RCTFileReaderModule.h */; };
Expand Down Expand Up @@ -53,8 +49,6 @@
/* End PBXCopyFilesBuildPhase section */

/* Begin PBXFileReference section */
19461728225F085900E4E008 /* RCTBlobCollector.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCTBlobCollector.h; sourceTree = "<group>"; };
19461729225F085900E4E008 /* RCTBlobCollector.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = RCTBlobCollector.mm; sourceTree = "<group>"; };
358F4ED71D1E81A9004DF814 /* libRCTBlob.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libRCTBlob.a; sourceTree = BUILT_PRODUCTS_DIR; };
AD9A43C11DFC7126008DC588 /* RCTBlobManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; lineEnding = 0; path = RCTBlobManager.h; sourceTree = "<group>"; };
AD9A43C21DFC7126008DC588 /* RCTBlobManager.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = RCTBlobManager.mm; sourceTree = "<group>"; };
Expand All @@ -67,8 +61,6 @@
358F4ECE1D1E81A9004DF814 = {
isa = PBXGroup;
children = (
19461728225F085900E4E008 /* RCTBlobCollector.h */,
19461729225F085900E4E008 /* RCTBlobCollector.mm */,
ADDFBA6A1F33455F0064C998 /* RCTFileReaderModule.h */,
ADDFBA6B1F33455F0064C998 /* RCTFileReaderModule.m */,
AD9A43C11DFC7126008DC588 /* RCTBlobManager.h */,
Expand Down Expand Up @@ -97,7 +89,6 @@
buildActionMask = 2147483647;
files = (
AD0871161E215EC9007D136D /* RCTBlobManager.h in Headers */,
1946172A225F085900E4E008 /* RCTBlobCollector.h in Headers */,
ADDFBA6C1F33455F0064C998 /* RCTFileReaderModule.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand All @@ -107,7 +98,6 @@
buildActionMask = 2147483647;
files = (
19BA88FF1F84392900741C5A /* RCTFileReaderModule.h in Headers */,
1946172B225F085900E4E008 /* RCTBlobCollector.h in Headers */,
AD0871181E215ED1007D136D /* RCTBlobManager.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down Expand Up @@ -172,7 +162,6 @@
developmentRegion = English;
hasScannedForEncodings = 0;
knownRegions = (
English,
en,
);
mainGroup = 358F4ECE1D1E81A9004DF814;
Expand All @@ -191,7 +180,6 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
1946172C225F085900E4E008 /* RCTBlobCollector.mm in Sources */,
ADDFBA6D1F33455F0064C998 /* RCTFileReaderModule.m in Sources */,
AD9A43C31DFC7126008DC588 /* RCTBlobManager.mm in Sources */,
);
Expand All @@ -201,7 +189,6 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
1946172D225F085900E4E008 /* RCTBlobCollector.mm in Sources */,
19BA89011F84393D00741C5A /* RCTFileReaderModule.m in Sources */,
ADD01A711E09404A00F6D226 /* RCTBlobManager.mm in Sources */,
);
Expand Down
30 changes: 0 additions & 30 deletions Libraries/Blob/RCTBlobCollector.h

This file was deleted.

52 changes: 0 additions & 52 deletions Libraries/Blob/RCTBlobCollector.mm

This file was deleted.

4 changes: 0 additions & 4 deletions Libraries/Blob/RCTBlobManager.mm
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
#import <React/RCTNetworking.h>
#import <React/RCTUtils.h>
#import <React/RCTWebSocketModule.h>
#import "RCTBlobCollector.h"

static NSString *const kBlobURIScheme = @"blob";

Expand All @@ -34,16 +33,13 @@ @implementation RCTBlobManager
RCT_EXPORT_MODULE(BlobModule)

@synthesize bridge = _bridge;
@synthesize methodQueue = _methodQueue;

- (void)setBridge:(RCTBridge *)bridge
{
_bridge = bridge;

std::lock_guard<std::mutex> lock(_blobsMutex);
_blobs = [NSMutableDictionary new];

facebook::react::RCTBlobCollector::install(self);
}

+ (BOOL)requiresMainQueueSetup
Expand Down

1 comment on commit 05baf62

@hramos
Copy link
Contributor

@hramos hramos commented on 05baf62 May 7, 2019

Choose a reason for hiding this comment

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

This commit reverted #24405. A new PR was opened in #24745 to attempt to get these changes in.

Please sign in to comment.