2010-01-14 4 views
0

У нас есть такой кодобраз памяти iPhone утечка

NSData* imageData; 
UIImage* imageForData; 
UIImageView* imageView; 

NSData* imageData; 
UIImage* imageForData; 
UIImageView* imageView; 
    CellWithId * cell = [[CellWithId alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier]; 

CGRect frame; 
frame.origin.x = 5; 
frame.origin.y = 0; 
frame.size.height = 43; 
frame.size.width = 52; 

if ([[planDictionary objectAtIndex:indexPath.row] objectForKey:@"url"]!=[NSNull null]) { 
    imageData = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:[[planDictionary objectAtIndex:indexPath.row] objectForKey:@"url"]]]; 
    imageForData = [[UIImage alloc] initWithData:imageData]; 
    imageView = [[UIImageView alloc] initWithImage:imageForData]; 
    imageView.frame = frame; 
    [cell.contentView addSubview:imageView]; 
    [imageData release]; 
    [imageForData release]; 

}NSData* imageData; 
UIImage* imageForData; 
UIImageView* imageView; 
//CellWithId *cell = (CellWithId*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
// if (cell == nil) { 
CellWithId * cell = [[CellWithId alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier]; 
//} 

CGRect frame; 
frame.origin.x = 5; 
frame.origin.y = 0; 
frame.size.height = 43; 
frame.size.width = 52; 

if ([[planDictionary objectAtIndex:indexPath.row] objectForKey:@"url"]!=[NSNull null]) { 
    imageData = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:[[planDictionary objectAtIndex:indexPath.row] objectForKey:@"url"]]]; 
    imageForData = [[UIImage alloc] initWithData:imageData]; 
    imageView = [[UIImageView alloc] initWithImage:imageForData]; 
    imageView.frame = frame; 
    [cell.contentView addSubview:imageView]; 
    [imageData release]; 
    [imageForData release]; 

}else { 
    //imageForData = [UIImage imageNamed:@"Plans-Default-image.jpg"]; 
    imageForData = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"Plans-Default-image" ofType:@"jpg"]]; 

    imageView = [[UIImageView alloc] initWithImage:imageForData]; 
    imageView.frame = frame; 
    [cell.contentView addSubview:imageView]; 
} 

[imageView release]; 

Я не знаю, что это проблема, но ImageData = [[NSData Alloc] initWithContentsOfURL: [NSURL URLWithString: [[planDictionary objectAtIndex: indexPath.row] objectForKey: @ "URL"]]]; это место, которое всегда показывает утечки памяти. Пожалуйста, помогите мне отладить эту проблему.

+0

Какой объект говорит, что он просочился? – coneybeare

+0

Вы вставляли свой код дважды или это как выглядит ваш код? – FelixLam

ответ

1

Вы назначаете два CellWithId и никогда не выпускаете его. Похоже, что вы не применяете этот метод должным образом. Клетка вернулся в

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 

должен быть autoreleased:

CellWithId * cell = [[[CellWithId alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease]; 
// ... 
return (UITableViewCell *)cell; 

Кроме того, вы должны использовать dequeueReusableCellWithIdentifier:CellIdentifier должным образом, чтобы иметь достойную производительность.

Смежные вопросы