2011-02-10 106 views
0
當我建立和analize我的應用程序

,我得到了潛在的泄漏的代碼[array1 release] ...附近爲什麼它的發生有..?在此先感謝潛在的泄漏問題

- (void) touchOnFeaturedCatalog 
{ 
    searchId == 2; 
    //featuredCatalogName = @"23064_Leeds2010"; 

    //NSString *response = [ZoomCatalogAppDelegate getResponseFromServer:[NSString stringWithFormat:@"http://www.zoomcatalog.com/iphone/iphone.php?catalog=%@&iphone=Yes&pdf=No", featuredCatalogName]]; 

    NSString *response = [ZoomCatalogAppDelegate getResponseFromServer:@"http://www.zoomcatalog.com/iphone/supplier.php"]; 
    //NSString *response = [ZoomCatalogAppDelegate getResponseFromServer:@"http://test.atvescape.com/articles.php"]; 
    //NSLog(@"Response = %@", response); 
    NSArray *array = [response componentsSeparatedByString:@"##"]; 
    [array retain]; 

    for(int i = 0; i < array.count; i++) 
    { 
     NSLog(@"Trying outer loop.... %d, %@, %@", i, [array objectAtIndex:i], featuredCatalogName); 
     NSArray *array4 = [featuredCatalogName componentsSeparatedByString:[array objectAtIndex:i]]; 
     if(array4.count > 1) 
     { 
      response = [ZoomCatalogAppDelegate getResponseFromServer:[NSString stringWithFormat:@"http://www.zoomcatalog.com/iphone/catalog_search.php?tid2=%@&iphone=yes", [array objectAtIndex:i]]]; 
      NSArray *array3= [response componentsSeparatedByString:@"<br>"]; 
      //baseURL = [NSString stringWithFormat:@"%@", [array3 objectAtIndex:0]]; 




      global_ContentString = [NSString stringWithFormat:@"%@", [array3 objectAtIndex:2]];//(searchId == 1 ? [array objectAtIndex:2] : ([array objectAtIndex: isLineNameSearch ? 2 : 1]))]; 
      [global_ContentString retain]; 

     // NSLog(@"baseURL = %@", global_ContentString); 
      NSArray *array1 = [global_ContentString componentsSeparatedByString:@"@@#"]; 

      for(int j = 0; j < array1.count; j++) 
      { 
       NSArray *array2 = [[array1 objectAtIndex:j] componentsSeparatedByString:@"##"];   
       NSString *str = [NSString stringWithFormat:@"%@", [array2 objectAtIndex:0]]; 
       str = [str stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]; 
       if ([str caseInsensitiveCompare:featuredCatalogName] == NSOrderedSame) 
       { 

        global_ContentString = [ZoomCatalogAppDelegate getResponseFromServer:[NSString stringWithFormat:@"http://www.zoomcatalog.com/iphone/iphone.php?catalog=%@&iphone=Yes&pdf=No", [array2 objectAtIndex:5]]]; 
        baseURL = [NSString stringWithFormat:@"%@", [[global_ContentString componentsSeparatedByString:@"<br>"] objectAtIndex:0]]; 
        //global_ContentString = [NSString stringWithFormat:@"%@", [[global_ContentString componentsSeparatedByString:@"<br>"] objectAtIndex:1]]; 
        [global_ContentString retain]; 

        [global_MainPageController presentModalViewController:global_FullPageController animated:YES]; 
        //NSLog(@"$$$$$$$$$$$$$$$$$$$$$$ Catalog id = %@ $$$$$$$$$$$$$$$$$$$$$$$$$$", [array2 objectAtIndex:5]); 
        //[array1 release];memory leak 
        return; 
       } 
      // NSLog(@"Trying inner loop.... %d, %@, %@", j, str, featuredCatalogName); 

      } 


     } 

    // if([[array objectAtIndex:i] com 
    } 
    [array release]; 
    return; 
} 

對不起,所有..

+0

請粘貼完整的代碼(沒有缺少括號)以及格式化它。 – Eimantas

+0

你可以粘貼'構建和分析'結果的屏幕截圖嗎? – Robin

+0

'for'循環和條件結束? – Eimantas

回答

1

如果您只在本地使用對象(在創建它的方法中),則可以自動釋放它。通過便捷方法創建或返回的對象可用,直到函數調用結束。除非您需要其他地方的物品,否則我建議開通retain電話。經驗法則是,只要您撥打alloc,new,retaincopy即可釋放對象。但是,如果您使用便捷方法,則返回的對象將自動生成。

看起來你打電話[global_ContentString retain];,但卻無法調用相應的版本。

+0

'[數組保留];'for循環前和'[數組釋放];'是不必要的,或者 – petershine