iphone image is leaking, but where?
        Posted  
        
            by Brodie4598
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by Brodie4598
        
        
        
        Published on 2010-04-24T01:32:18Z
        Indexed on 
            2010/04/24
            1:43 UTC
        
        
        Read the original article
        Hit count: 415
        
the image that is being displayed in this code is leaking but I cant figure out how. What I have a tableview that displays images to be displayed. Each time a user selects an image, it should remove the old image, download a new one, then add it to the scroll view. But the old image is not being released and I cant figure out why...
-(void)tableView:(UITableView *)tableView
didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [imageView removeFromSuperview];
    self.imageView = nil;
    NSUInteger row = [indexPath row];
    NSString *tempC = [[NSString alloc]initWithFormat:@"http://www.website.com/%@_0001.jpg",[pdfNamesFinalArray objectAtIndex:row] ];
    chartFileName = tempC;
    pdfName = [pdfNamesFinalArray objectAtIndex:row];
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    NSArray* paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
                                                         NSUserDomainMask, YES);
    NSString *docsPath = [paths objectAtIndex:0];
    NSString *tempString = [[[NSString alloc]initWithFormat:@"%@/%@.jpg",docsPath,pdfName]autorelease];
    NSData *data = [NSData dataWithContentsOfFile:tempString];
    if (data != NULL){
        self.imageView = nil;
        [imageView removeFromSuperview];
        self.imageView = nil;
        UIImageView *tempImage = [[[UIImageView alloc]initWithImage:[UIImage imageWithData:data]]autorelease];
        self.imageView = tempImage;
        [data release];
        scrollView.contentSize = CGSizeMake(imageView.frame.size.width , imageView.frame.size.height);
        scrollView.maximumZoomScale = 1;
        scrollView.minimumZoomScale = .6;
        scrollView.clipsToBounds = YES;
        scrollView.delegate = self;
        [scrollView addSubview:imageView];
        scrollView.zoomScale = .37;
    }
    else {
        [data release];
        self.imageView = nil;
        [imageView removeFromSuperview];
        self.imageView = nil;
        activityIndicator.hidden = NO;
        getChartsButton.enabled = NO;
        chartListButton.enabled = NO;
        saveChartButton.enabled = NO;
        [NSThread detachNewThreadSelector:@selector(downloadImages) toTarget:self withObject:nil];
    }
chartPanel.hidden = YES;
}
-(void) downloadImages {
    NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
    self.imageView = nil;
    [imageView removeFromSuperview];
    NSURL *url = [[[NSURL alloc]initWithString:chartFileName]autorelease];
    NSData *data = [NSData dataWithContentsOfURL:url];
    UIImageView *tempImage = [[[UIImageView alloc]initWithImage:[UIImage imageWithData:data]]autorelease];
    self.imageView = tempImage;
    tempImage = nil;
    scrollView.contentSize = CGSizeMake(imageView.frame.size.width , imageView.frame.size.height);
    scrollView.maximumZoomScale = 1;
    scrollView.minimumZoomScale = .37;
    scrollView.clipsToBounds = YES;
    scrollView.delegate = self;
    [scrollView addSubview:imageView];
    scrollView.zoomScale = .6;
    activityIndicator.hidden = YES;
    getChartsButton.enabled = YES;
    chartListButton.enabled = YES;
    saveChartButton.enabled = YES;
    [pool drain];
    [pool release];
}
© Stack Overflow or respective owner