English 中文(简体)
iPhone:图像使用的记忆没有放风
原标题:iPhone: Memory used by images is not freed

I have this code below that loads images from the web. Those images are shown after clicking on a table cell, and they are reloaded every time the table cell is clicked. The point is that analyzing the memory allocation with "Instruments", when I go back from the detail view to the table, the memory occupied from the images is not freed.

Does anyone have any suggestion? I, of course, do all the release of the case... but it seems to don t help.

    NSError *error = nil;
    UIImage *img = nil;
    NSString *myurl = [IMG_SERVER_URL stringByAppendingString: tmp_link.url];
    [UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
    NSData *imageData = nil;
    if(myurl!=nil){
        imageData = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:myurl] options:nil error:&error];
        if (error == 0) {
            img = [[UIImage alloc] initWithData:imageData];
        }
    }
    [imageData release]; imageData = nil;
    UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(targetWidth*i, 0, targetWidth, targetHeight)]; 
    imageView.image = img; 
    imageView.contentMode = UIViewContentModeScaleAspectFit;
    [img release];
    [....some code....]
    [imageView release];
问题回答

我认为,“imageView.image = img”增加了图像物体的参考值。 如果我有权的话,只要你不发表图像意见,所分配的记忆就不会被解放。





相关问题
Code sign Error

I have created a new iPhone application.I have two mach machines. I have created the certificate for running application in iPhone in one mac. Can I use the other mac for running the application in ...

ABPersonViewController Usage for displaying contact

Created a View based Project and added a contact to the AddressBook using ABAddressBookRef,ABRecordRef now i wanted to display the added contact ABPersonViewController is the method but how to use in ...

将音频Clips从Peter改为服务器

我不禁要问,那里是否有任何实例表明从Peit向服务器发送音响。 I m不关心电话或SIP风格的解决办法,只是一个简单的袖珍流程......

• 如何将搜查线重新定位?

我正试图把图像放在搜索条左边。 但是,问题始于这里,搜索条线不能重新布署。

热门标签