2010-01-14 3 views
0

우리는 나는 문제가 무엇인지 잘 모릅니다이아이폰 이미지 메모리는

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 

는 오토 릴리즈해야한다 반환 :

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

은 또한 당신이 괜찮은 성능을 가지고 제대로 dequeueReusableCellWithIdentifier:CellIdentifier를 사용해야합니다.