From 44b6831ede46e647cce831954d73eee3e63978a1 Mon Sep 17 00:00:00 2001 From: robzyb <> Date: Tue, 3 Sep 2019 19:09:45 +1000 Subject: [PATCH] memory leak implementation --- App.js | 11 +++++ ios/DataProvider.swift | 41 +++++++++++++++++++ ios/DataProviderBridge.m | 15 +++++++ ios/poc-Bridging-Header.h | 6 +++ ios/poc.xcodeproj/project.pbxproj | 24 ++++++++++- .../xcshareddata/IDEWorkspaceChecks.plist | 8 ++++ .../AppIcon.appiconset/Contents.json | 15 +++++++ 7 files changed, 119 insertions(+), 1 deletion(-) create mode 100644 ios/DataProvider.swift create mode 100644 ios/DataProviderBridge.m create mode 100644 ios/poc-Bridging-Header.h create mode 100644 ios/poc.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist diff --git a/App.js b/App.js index a0076ec..1531a48 100644 --- a/App.js +++ b/App.js @@ -8,6 +8,8 @@ import React, {Fragment} from 'react'; import { + NativeEventEmitter, + NativeModules, SafeAreaView, StyleSheet, ScrollView, @@ -23,8 +25,17 @@ import { DebugInstructions, ReloadInstructions, } from 'react-native/Libraries/NewAppScreen'; +// import console = require('console'); const App = () => { + var DataProvider = NativeModules.DataProvider; + const dataProviderEmitter = new NativeEventEmitter(DataProvider); + const subscription = dataProviderEmitter.addListener( + 'NewData', + (body) => {} + ); + DataProvider.start(); + console.log("Started App"); return ( diff --git a/ios/DataProvider.swift b/ios/DataProvider.swift new file mode 100644 index 0000000..e120cb6 --- /dev/null +++ b/ios/DataProvider.swift @@ -0,0 +1,41 @@ +import Foundation + +@objc(DataProvider) +class DataProvider: RCTEventEmitter { + + var timer: Timer? = nil + + @objc + func start() -> Void { + stop() + timer = Timer.scheduledTimer(timeInterval: 0.1, target: self, selector: #selector(sendData), userInfo: nil, repeats: true) + self.sendEvent(withName: ("NewData"), body: "started") + } + + @objc + func stop() -> Void { + guard let timer = timer else { return } + timer.invalidate() + self.timer = nil + } + + @objc + func sendData() + { + let data = Array(repeating:0, count:10000) + self.sendEvent(withName: ("NewData"), body: data as NSArray) + } + + @objc + override func supportedEvents() -> [String] { + return ["NewData"] + } + + // React Native gives a warning that RCTEventEmitter needs requiresMainQueueSetup + @objc + override static func requiresMainQueueSetup() -> Bool + { + return true; + } + +} diff --git a/ios/DataProviderBridge.m b/ios/DataProviderBridge.m new file mode 100644 index 0000000..e9fafa2 --- /dev/null +++ b/ios/DataProviderBridge.m @@ -0,0 +1,15 @@ +#import +#import + +@interface RCT_EXTERN_MODULE(DataProvider, RCTEventEmitter) + +RCT_EXTERN_METHOD(start) +RCT_EXTERN_METHOD(stop) + +// This is needed so the timer runs correctly +- (dispatch_queue_t)methodQueue +{ + return dispatch_get_main_queue(); +} + +@end diff --git a/ios/poc-Bridging-Header.h b/ios/poc-Bridging-Header.h new file mode 100644 index 0000000..ebf12f6 --- /dev/null +++ b/ios/poc-Bridging-Header.h @@ -0,0 +1,6 @@ +// +// Use this file to import your target's public headers that you would like to expose to Swift. +// + +#import +#import diff --git a/ios/poc.xcodeproj/project.pbxproj b/ios/poc.xcodeproj/project.pbxproj index 0189b94..08eb204 100644 --- a/ios/poc.xcodeproj/project.pbxproj +++ b/ios/poc.xcodeproj/project.pbxproj @@ -19,6 +19,8 @@ 36A99127BDE24423D2886A1C /* libPods-poc-tvOSTests.a in Frameworks */ = {isa = PBXBuildFile; fileRef = B850509D60E319D741BA0402 /* libPods-poc-tvOSTests.a */; }; 5852F77ACF7C03370460BB7F /* libPods-poc-tvOS.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 6B70F634D135F7FE92938109 /* libPods-poc-tvOS.a */; }; 7D2F952AAD8B6AC27095FC4A /* libPods-poc.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 37C75068D22C67C5931F61E4 /* libPods-poc.a */; }; + D4A4CEFE231E4C7C0067257C /* DataProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = D4A4CEFD231E4C7C0067257C /* DataProvider.swift */; }; + D4A4CF00231E4D170067257C /* DataProviderBridge.m in Sources */ = {isa = PBXBuildFile; fileRef = D4A4CEFF231E4D170067257C /* DataProviderBridge.m */; }; E272666510575BF7F35FBBAD /* libPods-pocTests.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 9898C871177B07C4C9968B87 /* libPods-pocTests.a */; }; /* End PBXBuildFile section */ @@ -64,6 +66,9 @@ BE8E6741CBCC61E2DE3F966E /* Pods-poc-tvOS.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-poc-tvOS.release.xcconfig"; path = "Target Support Files/Pods-poc-tvOS/Pods-poc-tvOS.release.xcconfig"; sourceTree = ""; }; C2D77E4DDDC906A44894594C /* Pods-poc-tvOSTests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-poc-tvOSTests.debug.xcconfig"; path = "Target Support Files/Pods-poc-tvOSTests/Pods-poc-tvOSTests.debug.xcconfig"; sourceTree = ""; }; C7EB3AA69D0CF9CEE665CAB2 /* Pods-poc-tvOSTests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-poc-tvOSTests.release.xcconfig"; path = "Target Support Files/Pods-poc-tvOSTests/Pods-poc-tvOSTests.release.xcconfig"; sourceTree = ""; }; + D4A4CEFC231E4C7C0067257C /* poc-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "poc-Bridging-Header.h"; sourceTree = ""; }; + D4A4CEFD231E4C7C0067257C /* DataProvider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DataProvider.swift; sourceTree = ""; }; + D4A4CEFF231E4D170067257C /* DataProviderBridge.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = DataProviderBridge.m; sourceTree = ""; }; E4C1D3BDBFA52FF8D517845F /* Pods-pocTests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-pocTests.release.xcconfig"; path = "Target Support Files/Pods-pocTests/Pods-pocTests.release.xcconfig"; sourceTree = ""; }; ED297162215061F000B7C4FE /* JavaScriptCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = JavaScriptCore.framework; path = System/Library/Frameworks/JavaScriptCore.framework; sourceTree = SDKROOT; }; ED2971642150620600B7C4FE /* JavaScriptCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = JavaScriptCore.framework; path = Platforms/AppleTVOS.platform/Developer/SDKs/AppleTVOS12.0.sdk/System/Library/Frameworks/JavaScriptCore.framework; sourceTree = DEVELOPER_DIR; }; @@ -132,6 +137,9 @@ 13B07FB61A68108700A75B9A /* Info.plist */, 13B07FB11A68108700A75B9A /* LaunchScreen.xib */, 13B07FB71A68108700A75B9A /* main.m */, + D4A4CEFD231E4C7C0067257C /* DataProvider.swift */, + D4A4CEFF231E4D170067257C /* DataProviderBridge.m */, + D4A4CEFC231E4C7C0067257C /* poc-Bridging-Header.h */, ); name = poc; sourceTree = ""; @@ -194,7 +202,6 @@ 9CA4C50BB2C2A84C641E37FD /* Pods-pocTests.debug.xcconfig */, E4C1D3BDBFA52FF8D517845F /* Pods-pocTests.release.xcconfig */, ); - name = Pods; path = Pods; sourceTree = ""; }; @@ -292,6 +299,9 @@ CreatedOnToolsVersion = 6.2; TestTargetID = 13B07F861A680F5B00A75B9A; }; + 13B07F861A680F5B00A75B9A = { + LastSwiftMigration = 1030; + }; 2D02E47A1E0B4A5D006451C7 = { CreatedOnToolsVersion = 8.2.1; ProvisioningStyle = Automatic; @@ -308,6 +318,7 @@ developmentRegion = English; hasScannedForEncodings = 0; knownRegions = ( + English, en, Base, ); @@ -528,6 +539,8 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + D4A4CEFE231E4C7C0067257C /* DataProvider.swift in Sources */, + D4A4CF00231E4D170067257C /* DataProviderBridge.m in Sources */, 13B07FBC1A68108700A75B9A /* AppDelegate.m in Sources */, 13B07FC11A68108700A75B9A /* main.m in Sources */, ); @@ -582,6 +595,7 @@ isa = XCBuildConfiguration; baseConfigurationReference = 9CA4C50BB2C2A84C641E37FD /* Pods-pocTests.debug.xcconfig */; buildSettings = { + ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; BUNDLE_LOADER = "$(TEST_HOST)"; GCC_PREPROCESSOR_DEFINITIONS = ( "DEBUG=1", @@ -605,6 +619,7 @@ isa = XCBuildConfiguration; baseConfigurationReference = E4C1D3BDBFA52FF8D517845F /* Pods-pocTests.release.xcconfig */; buildSettings = { + ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; BUNDLE_LOADER = "$(TEST_HOST)"; COPY_PHASE_STRIP = NO; INFOPLIST_FILE = pocTests/Info.plist; @@ -626,6 +641,7 @@ baseConfigurationReference = 67EE55C7998D87E084B39206 /* Pods-poc.debug.xcconfig */; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CLANG_ENABLE_MODULES = YES; CURRENT_PROJECT_VERSION = 1; DEAD_CODE_STRIPPING = NO; INFOPLIST_FILE = poc/Info.plist; @@ -637,6 +653,9 @@ ); PRODUCT_BUNDLE_IDENTIFIER = "org.reactjs.native.example.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = poc; + SWIFT_OBJC_BRIDGING_HEADER = "poc-Bridging-Header.h"; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + SWIFT_VERSION = 5.0; VERSIONING_SYSTEM = "apple-generic"; }; name = Debug; @@ -646,6 +665,7 @@ baseConfigurationReference = AB77AB52BEFC2A6FD019387F /* Pods-poc.release.xcconfig */; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CLANG_ENABLE_MODULES = YES; CURRENT_PROJECT_VERSION = 1; INFOPLIST_FILE = poc/Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; @@ -656,6 +676,8 @@ ); PRODUCT_BUNDLE_IDENTIFIER = "org.reactjs.native.example.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = poc; + SWIFT_OBJC_BRIDGING_HEADER = "poc-Bridging-Header.h"; + SWIFT_VERSION = 5.0; VERSIONING_SYSTEM = "apple-generic"; }; name = Release; diff --git a/ios/poc.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/ios/poc.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 0000000..18d9810 --- /dev/null +++ b/ios/poc.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + diff --git a/ios/poc/Images.xcassets/AppIcon.appiconset/Contents.json b/ios/poc/Images.xcassets/AppIcon.appiconset/Contents.json index 118c98f..19882d5 100644 --- a/ios/poc/Images.xcassets/AppIcon.appiconset/Contents.json +++ b/ios/poc/Images.xcassets/AppIcon.appiconset/Contents.json @@ -1,5 +1,15 @@ { "images" : [ + { + "idiom" : "iphone", + "size" : "20x20", + "scale" : "2x" + }, + { + "idiom" : "iphone", + "size" : "20x20", + "scale" : "3x" + }, { "idiom" : "iphone", "size" : "29x29", @@ -29,6 +39,11 @@ "idiom" : "iphone", "size" : "60x60", "scale" : "3x" + }, + { + "idiom" : "ios-marketing", + "size" : "1024x1024", + "scale" : "1x" } ], "info" : {