任何想法爲什麼下面的行會泄漏內存?這條線爲什麼會泄漏內存?
cell.imageView.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:person.imageURL]];
的方法的cellForRowAtIndexPath內:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"PersonCell"];
if (cell == nil){
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:@"PersonCell"] autorelease];
}
Person *person = [[Person alloc] initWithUserName:[people objectAtIndex:indexPath.row]];
cell.imageView.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:person.imageURL]];
cell.textLabel.text = [people objectAtIndex:indexPath.row];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
[person release];
return cell;
}
這裏是從person.m相關方法
- (NSURL*) imageURL
{
return [NSURL URLWithString:[userInfo valueForKey:@"profile_image_url"]];
}
編輯:添加init方法:
- (id)initWithUserName:(NSString *)user{
userName = [user copy];
userInfo = [[TwitterHelper fetchInfoForUsername:userName] retain];
updates = [[TwitterHelper fetchTimelineForUsername:userName] retain];
return self;
}
你怎麼知道它在泄漏?正如傑森所說的那樣, – 2009-09-09 21:36:10
;你怎麼確定它正在泄漏?你使用了什麼工具? – bbum 2009-09-09 22:00:01
我正在儀器上運行它來觀察泄漏。這就是這些工具正在報告的內容。 – Jason 2009-09-10 13:15:01