Objective c 潜在泄漏问题
当我构建并分析我的应用程序时,我发现代码附近有潜在的泄漏Objective c 潜在泄漏问题,objective-c,ios,memory-management,Objective C,Ios,Memory Management,当我构建并分析我的应用程序时,我发现代码附近有潜在的泄漏[array1 release]…为什么会发生这种情况?请提前感谢 - (void) touchOnFeaturedCatalog { searchId == 2; //featuredCatalogName = @"23064_Leeds2010"; //NSString *response = [ZoomCatalogAppDelegate getResponseFromServer:[NSString str
[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;
}
-(无效)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*数组=[响应组件由字符串分隔:@“##”];
[阵列保留];
对于(int i=0;i1)
{
response=[ZoomCatalogAppDelegate getResponseFromServer:[NSString stringWithFormat:@]http://www.zoomcatalog.com/iphone/catalog_search.php?tid2=%@&iphone=yes“,[array objectAtIndex:i]];
NSArray*array3=[由字符串分隔的响应组件:@“
”;
//baseURL=[NSString stringWithFormat:@“%@,[array3 objectAtIndex:0]];
全局内容字符串=[NSString stringWithFormat:@“%@,[array3 objectAtIndex:2]];/(搜索ID==1?[array objectAtIndex:2]:([array objectAtIndex:isLineNameSearch?2:1]);
[全局内容字符串保留];
//NSLog(@“baseURL=%@”,全局内容字符串);
NSArray*array1=[全局内容字符串组件由字符串分隔:@“@”和“@”;
对于(int j=0;j”]objectAtIndex:0]];
//全局内容字符串=[NSString stringWithFormat:@“%@,[[global\U ContentString Components由字符串分离:@”
“]objectAtIndex:1]];
[全局内容字符串保留];
[global_Main PageController presentModalViewController:global_FullPageController动画:是];
//NSLog(@“$$$$$$$$$$$$$$目录id=%@$$$$$$$$$$”,[array2 objectAtIndex:5]);
//[array1释放];内存泄漏
返回;
}
//NSLog(@“正在尝试内部循环….%d、%@、%@)、j、str、featuredCatalogName);
}
}
//if([[array objectAtIndex:i]com
}
[阵列释放];
返回;
}
抱歉,如果您仅在本地使用对象(在创建对象的方法中),那么您可以自动释放它。通过方便方法创建或返回的对象在函数调用结束前可用。除非您在其他地方需要这些对象,否则我建议放弃
retain
调用。经验法则是,无论何时调用alloc
、new
、retain
或copy
,您都可以释放对象。但是,如果使用方便的方法,返回的对象将自动生成
您似乎调用了
[global_ContentString retain];
,但未能调用相应的版本。请粘贴完整的代码(不缺少括号)以及格式化。你能粘贴构建和分析的结果的屏幕截图吗for
循环和条件在哪里结束?这很难理解。而且,我看不出你有什么理由释放array1,你应该释放global_ContentString。代码中似乎缺少右括号。我尝试了清理正在设置格式,但无法确定格式的开头或结尾。[array retain];
在for循环之前;[array release];
也不是必需的