English 中文(简体)
潜在的泄漏问题
原标题:potential leak problems

当我构建和分析我的应用程序时,在代码[array1release]附近有潜在的泄漏。。。为什么会发生在那里。。?提前感谢

- (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;
}

对不起。。

最佳回答

如果您只在本地(在创建对象的方法中)使用对象,您可以自动释放它。由方便方法创建或返回的对象在函数调用结束前都可用。除非您在其他地方需要对象,否则我建议放弃retain调用。经验法则是,无论何时调用allocnewretaincopy都会释放对象。但是,如果使用方便的方法,返回的对象将自动生成。

似乎您调用了<code>〔global_ContentString retain〕,但随后无法调用相应的发行版。

问题回答

暂无回答




相关问题
List Contents of Directory in a UITableView

I am trying to list the contents of Ringtones directory in a TableView, however, I am only getting the last file in the directory in ALL cells, instead of file per cell. This is my code: - (...

iPhone NSUserDefaults persistance difficulty

In my app i have a bunch of data i store in the NSUserdefaults. This information consists of an NSObject (Object1) with NSStrings and NSNumbers and also 2 instances of yet another object (Object2). ...

Writing a masked image to disk as a PNG file

Basically I m downloading images off of a webserver and then caching them to the disk, but before I do so I want to mask them. I m using the masking code everyone seems to point at which can be found ...

Resize UIImage with aspect ratio?

I m using this code to resize an image on the iPhone: CGRect screenRect = CGRectMake(0, 0, 320.0, 480.0); UIGraphicsBeginImageContext(screenRect.size); [value drawInRect:screenRect blendMode:...

Allowing interaction with a UIView under another UIView

Is there a simple way of allowing interaction with a button in a UIView that lies under another UIView - where there are no actual objects from the top UIView on top of the button? For instance, ...

热门标签