我試圖刪除我的應用程序中的內存泄漏,但我發現在for循環中使用alloc NSbundle時,它給我內存泄漏。儀器在for循環中使用NSbundle時給內存泄漏
這裏是我的代碼: -
in my class myFeed.m
for(int i = 0; i<20; i++)
{
NSAutoreleasePool *pool=[[NSAutoreleasePool alloc]init];
NSDictionary *temp = (NSDictionary*)[topData objectAtIndex:i];
NSString *iconName = [temp objectForKey:@"feed_source"];
NSString *imageName;
TimeLineGrid *grid = [[TimeLineGrid alloc]initWithNibName:@"TimeLineGrid" bundle:[NSBundle mainBundle]];
CGRect frame = grid.view.frame;
if([iconName isEqualToString:@"Youtube"])
imageName = [[NSBundle mainBundle]pathForResource:@"Youtube" ofType:@"png"];;
if (UIInterfaceOrientationIsLandscape(self.interfaceOrientation))
{
frame.size=CGSizeMake(130, 130);
}
else
{
frame.size = CGSizeMake(180, 180);
}
[grid setDelegate:self];
if (isConditionTrue)
{
x = x - 200 - topFactor;
}
else
x = x - frame.size.width;
if (x < 0)
{
x = 0;
}
frame.origin.x = x;
frame.origin.y = y;
grid.view.frame = frame;
grid.view.tag = tagCount;
if ([temp objectForKey:@"feed_item_nid"])
{
[tagToNIDMap addObject:[temp objectForKey:@"feed_item_nid"]];
}
if ([(NSString*)[temp objectForKey:@"feed_source"]isEqualToString:@"Youtube"])
{
[grid.webView loadHTMLString:[self getYoutubeCode:(NSString*)[temp objectForKey:@"feed_item_url"] :grid.webView.frame] baseURL:nil];
}
else
{
NSString * str = [[WebServiceController Initialize]parseHTMLData:[temp objectForKey:@"feed_item_body"] : @"//img"];
NSURL * url = [NSURL URLWithString:str];
NSURLRequest * req = [NSURLRequest requestWithURL:url];
[grid.webView loadRequest:req];
}
//[grid.view addSubview:grid.webView];
tagCount++;
[grid setHome:frame];
grid.dict = (NSDictionary*)[topData objectAtIndex:i];
// grid.icon.frame=CGRectMake(grid.view.frame.origin.x, grid.view.frame.origin.y-20,grid.icon.frame.size.width,grid.icon.frame.size.height)
grid.icon.image = [UIImage imageNamed:imageName];
grid.detail.text = [temp objectForKey:@"feed_item_title"];
[scroll1 addSubview:grid.view];
[imageName release];
[grid release];
[pool release];
}
}
myGrid是用的.xib我正努力在myFeed類加載的類。 但如果在循環結束時添加[grid release]
,則可以看到myGrid的視圖,但myGrid中存在的UiwebView不顯示其數據。 ,儀器也顯示出內存泄漏在該行:
myGrid *grid = [[myGrid alloc]initWithNibName:@"myGrid" bundle:[NSBundle mainBundle]];
我在做什麼錯在這裏...
你在哪裏插入'[grid release]'?這是需要的 – Nekto
我已經添加了[網格發佈]代碼 –