Madhumitha
Madhumitha

Reputation: 3824

potential leak problems

when I build and analize my application , am getting potential leak near the code [array1 release]...why its happening there..?thanks in advance

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

sorry for all..

Upvotes: 0

Views: 362

Answers (1)

Moshe
Moshe

Reputation: 58067

If you are only using an object locally (within the method in which it is created) you can autorelease it. Objects that are created or returned by convenience methods available until the end of the function call. Unless you need the objects elsewhere, I suggest ditching the retain calls. The rule of thumb is that whenever you call alloc, new, retain, or copy you mist release the object. However, if you use a convenience method, The returned object is autogenerate for you.

It seems that you call [global_ContentString retain]; but then fail to call a corresponding release.

Upvotes: 1

Related Questions