From a65d12a57bf9fd2187d5f7da4db303cfbb3a093c Mon Sep 17 00:00:00 2001 From: Li Zheng Date: Sat, 28 May 2022 15:00:37 +0800 Subject: [PATCH] fix: iOS memory leak when recreate canvas #42 --- ios/BridgeModule/GCanvasModule.h | 2 ++ ios/BridgeModule/GCanvasModule.m | 8 ++++++++ ios/RCTGCanvasModule.m | 1 + 3 files changed, 11 insertions(+) diff --git a/ios/BridgeModule/GCanvasModule.h b/ios/BridgeModule/GCanvasModule.h index 7adf10ba..7031edc6 100644 --- a/ios/BridgeModule/GCanvasModule.h +++ b/ios/BridgeModule/GCanvasModule.h @@ -55,6 +55,8 @@ typedef void (^GCanvasModuleCallback)(id result); */ - (NSString*)enable:(NSDictionary *)args; +- (void)disable:(NSString*)componentId; + #pragma mark - Export Method of Context2D /** * Export JS method for reset GCanvas component while disappear diff --git a/ios/BridgeModule/GCanvasModule.m b/ios/BridgeModule/GCanvasModule.m index 65b3d2cb..63701cc9 100644 --- a/ios/BridgeModule/GCanvasModule.m +++ b/ios/BridgeModule/GCanvasModule.m @@ -182,6 +182,14 @@ - (NSString*)enable:(NSDictionary *)args{ return @"true"; } +- (void)disable:(NSString*)componentId{ + GCVLOG_METHOD(@"disable:, componentId=%@", componentId); + + [[NSNotificationCenter defaultCenter] postNotificationName:kGCanvasDestroyNotification + object:nil + userInfo:@{@"instanceId":[self.deletage gcanvasModuleInstanceId]}]; +} + #pragma mark - Need Export Context2D Method /** * Export JS method for reset GCanvas component while disappear diff --git a/ios/RCTGCanvasModule.m b/ios/RCTGCanvasModule.m index a62e012c..711af0be 100644 --- a/ios/RCTGCanvasModule.m +++ b/ios/RCTGCanvasModule.m @@ -78,6 +78,7 @@ - (dispatch_queue_t)methodQueue RCT_EXPORT_METHOD(disable:(NSString*) componentId) { + [self.gcanvasModule disable:componentId]; } //preload image