diff --git a/ios/sdk/WeexSDK/Sources/Model/WXSDKInstance.m b/ios/sdk/WeexSDK/Sources/Model/WXSDKInstance.m index 87bc32650b..613abd59a4 100644 --- a/ios/sdk/WeexSDK/Sources/Model/WXSDKInstance.m +++ b/ios/sdk/WeexSDK/Sources/Model/WXSDKInstance.m @@ -78,7 +78,6 @@ @implementation WXSDKInstance BOOL _debugJS; id _instanceJavaScriptContext; // sandbox javaScript context CGFloat _defaultPixelScaleFactor; - BOOL _bReleaseInstanceInMainThread; BOOL _defaultDataRender; } @@ -118,7 +117,6 @@ - (instancetype)init _apmInstance = [[WXApmForInstance alloc] init]; _defaultPixelScaleFactor = CGFLOAT_MIN; - _bReleaseInstanceInMainThread = YES; _defaultDataRender = NO; [self addObservers]; @@ -443,9 +441,6 @@ - (BOOL)_handleConfigCenter BOOL useJSCApiForCreateInstance = [[configCenter configForKey:@"iOS_weex_ext_config.useJSCApiForCreateInstance" defaultValue:@(YES) isDefault:NULL] boolValue]; [WXUtility setUseJSCApiForCreateInstance:useJSCApiForCreateInstance]; - - //Reading config from orange for Release instance in Main Thread or not - _bReleaseInstanceInMainThread = [[configCenter configForKey:@"iOS_weex_ext_config.releaseInstanceInMainThread" defaultValue:@(YES) isDefault:nil] boolValue]; BOOL shoudMultiContext = NO; shoudMultiContext = [[configCenter configForKey:@"iOS_weex_ext_config.createInstanceUsingMutliContext" defaultValue:@(YES) isDefault:NULL] boolValue]; @@ -659,13 +654,9 @@ - (void)destroyInstance [WXCoreBridge closePage:instanceId]; // Reading config from orange for Release instance in Main Thread or not, for Bug #15172691 +{ - if (!_bReleaseInstanceInMainThread) { + dispatch_async(dispatch_get_main_queue(), ^{ [WXSDKManager removeInstanceforID:instanceId]; - } else { - dispatch_async(dispatch_get_main_queue(), ^{ - [WXSDKManager removeInstanceforID:instanceId]; - }); - } + }); //+} }); diff --git a/ios/sdk/WeexSDK/Sources/Utility/WXThreadSafeMutableDictionary.m b/ios/sdk/WeexSDK/Sources/Utility/WXThreadSafeMutableDictionary.m index 3c32292269..6f31fb990e 100644 --- a/ios/sdk/WeexSDK/Sources/Utility/WXThreadSafeMutableDictionary.m +++ b/ios/sdk/WeexSDK/Sources/Utility/WXThreadSafeMutableDictionary.m @@ -145,24 +145,30 @@ - (NSEnumerator *)keyEnumerator - (void)setObject:(id)anObject forKey:(id)aKey { + id originalObject = nil; // make sure that object is not released in lock @try { pthread_mutex_lock(&_safeThreadDictionaryMutex); + originalObject = [_dict objectForKey:aKey]; [_dict setObject:anObject forKey:aKey]; } @finally { pthread_mutex_unlock(&_safeThreadDictionaryMutex); } + originalObject = nil; } - (void)setObject:(id)anObject forKeyedSubscript:(id )key { + id originalObject = nil; // make sure that object is not released in lock @try { pthread_mutex_lock(&_safeThreadDictionaryMutex); + originalObject = [_dict objectForKey:key]; [_dict setObject:anObject forKeyedSubscript:key]; } @finally { pthread_mutex_unlock(&_safeThreadDictionaryMutex); } + originalObject = nil; } - (NSArray *)allKeys @@ -189,24 +195,32 @@ - (NSArray *)allValues - (void)removeObjectForKey:(id)aKey { + id originalObject = nil; // make sure that object is not released in lock @try { pthread_mutex_lock(&_safeThreadDictionaryMutex); - [_dict removeObjectForKey:aKey]; + originalObject = [_dict objectForKey:aKey]; + if (originalObject) { + [_dict removeObjectForKey:aKey]; + } } @finally { pthread_mutex_unlock(&_safeThreadDictionaryMutex); } + originalObject = nil; } - (void)removeAllObjects { + NSArray* allValues = nil; // make sure that objects are not released in lock @try { pthread_mutex_lock(&_safeThreadDictionaryMutex); + allValues = [_dict allValues]; [_dict removeAllObjects]; } @finally { pthread_mutex_unlock(&_safeThreadDictionaryMutex); } + allValues = nil; } - (id)copy