From 90f535d86e1a234383fac202a4cd92d5aba2e9f7 Mon Sep 17 00:00:00 2001 From: acton393 Date: Wed, 15 Nov 2017 17:08:20 +0800 Subject: [PATCH] [WEEX-120][iOS]try to optimize unload weex component try to reduce context switch when unload component. Bug:120 --- .../Sources/Manager/WXComponentManager.m | 24 +++++++------------ 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/ios/sdk/WeexSDK/Sources/Manager/WXComponentManager.m b/ios/sdk/WeexSDK/Sources/Manager/WXComponentManager.m index 691f713870..4f6c06c256 100644 --- a/ios/sdk/WeexSDK/Sources/Manager/WXComponentManager.m +++ b/ios/sdk/WeexSDK/Sources/Manager/WXComponentManager.m @@ -711,25 +711,19 @@ - (void)refreshFinish - (void)unload { WXAssertComponentThread(); - - NSEnumerator *enumerator = [_indexDict objectEnumerator]; - WXComponent *component; - while ((component = [enumerator nextObject])) { - dispatch_async(dispatch_get_main_queue(), ^{ + [self invalidate]; + [self _stopDisplayLink]; + NSEnumerator *enumerator = [[_indexDict copy] objectEnumerator]; + dispatch_async(dispatch_get_main_queue(), ^{ + WXComponent *component; + while ((component = [enumerator nextObject])) { [component _unloadViewWithReusing:NO]; - }); - } + } + _rootComponent = nil; + }); [_indexDict removeAllObjects]; [_uiTaskQueue removeAllObjects]; - - dispatch_async(dispatch_get_main_queue(), ^{ - _rootComponent = nil; - }); - - [self _stopDisplayLink]; - - _isValid = NO; } - (void)invalidate