gpt4 book ai didi

objective-c - 潜在的泄漏问题

转载 作者:行者123 更新时间:2023-11-29 05:06:26 25 4
gpt4 key购买 nike

当我构建并分析我的应用程序时,我在代码[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;
}

对不起大家..

最佳答案

如果您仅在本地使用对象(在创建该对象的方法内),则可以自动释放它。由便捷方法创建或返回的对象在函数调用结束之前可用。除非您在其他地方需要这些对象,否则我建议放弃 retain 调用。经验法则是,每当您调用 allocnewretaincopy 时,您都必须释放该对象。但是,如果您使用便捷方法,则返回的对象会为您自动生成。

您似乎调用了[global_ContentString keep];,但随后无法调用相应的版本。

关于objective-c - 潜在的泄漏问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4953555/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com