2013-02-01 25 views
0

我收到此消息「胎面9:EXC_BAD_ACCESS(碼= 1,地址= 0x70000010)在該方法中(但這個錯誤被創建僅當在另一個線程文件正被下載):胎面9:EXC_BAD_ACCESS

- (NSMutableDictionary *) getDictionaryAllStatin:(sqlite3*)database 
{ 

    if (self._streetsArrey == nil || self._streetsArrey.count <= 0) { 
     [self getArrayAllStatin:database]; 
    } 

    /*--------------------------------------------------------------*/ 
    NSMutableDictionary *result1 = [[NSMutableDictionary alloc] init]; 

    for (StreetData *street in _streetsArrey) { 
     NSString * name = [self deleteContractionWithText:street._name]; 
     NSArray * arr = [name componentsSeparatedByString:@" "]; 
     NSMutableArray *arrm = [[NSMutableArray alloc] initWithArray:arr]; 
     arr = nil; 
     [arrm addObject:name]; 

      for (NSString *txt in arrm) { 
       int lengthText = txt.length; 
       for (int i = 2 ; i <= lengthText; i++) { 
        NSString * key = [txt substringToIndex:i]; 
        key = [key lowercaseString]; 
        NSMutableDictionary *isSet = [result1 objectForKey:[NSNumber numberWithInt:[key hash]]]; 
        if (isSet == nil) { 
         isSet = [[NSMutableDictionary alloc]init]; 
        } 
        [isSet setObject:street forKey:[NSNumber numberWithInt:street._streetId]]; 
        [result1 setObject:isSet forKey:[NSNumber numberWithInt:[key hash]]]; 
        isSet = nil; 
        key = nil; 
       } 
      } 

    } 

    NSMutableDictionary *result = [[NSMutableDictionary alloc] init]; 
    for (id key in result1) { 
     NSMutableDictionary *dictionary = [result1 objectForKey:key]; 
     NSArray *arr = [dictionary allValues]; 
     [result setObject:arr forKey:key]; 
     arr = nil; 
     [dictionary removeAllObjects]; 
     dictionary = nil; 

    } 
    [result1 removeAllObjects]; 
    result1 = nil; 
    /*--------------------------------------------------------------*/ 
    if (result.count > 0) { 
     _streetsDictionary = result; 
     result = nil; 
     return _streetsDictionary; 
    }else { 
     _streetsDictionary = nil; 
     return nil; 
    } 
} 

enter image description here

enter image description here

爲什麼我得到這個消息?

我該如何解決?

+0

您可以使用斷點調試您的代碼。 – Buntylm

+0

))我做到了。但當我調試我的代碼,我沒有得到這個消息 – Vit

+0

檢查出你是否得到你的字典中的所有值 –

回答

2

崩潰最可能的原因是嘗試訪問已被釋放的對象。

因爲它似乎是故障發生就行了:

NSMutableDictionary *isSet = [result1 objectForKey:[NSNumber numberWithInt:[key hash]]]; 

我會建議分裂聲明下降到它的組件,試圖追查其對象實際上可能是罪魁禍首:

NSInteger h = [key hash]; 
NSNumber n = [NSNumber numberWithInt:h]; 
... 

但是隻有當正在下載另一個線程文件時纔會創建此錯誤

另外,檢查下載代碼和崩潰代碼是否有共同之處。前者可能會導致第二個對象的釋放。

希望它有幫助。