UIImage内存没有解除分配VM:ImageIO_JPEG_DATA? [英] UIImage memory not deallocating VM: ImageIO_JPEG_DATA?

查看:702
本文介绍了UIImage内存没有解除分配VM:ImageIO_JPEG_DATA?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一次在屏幕上有多个水平滚动的集合视图。他们都充满了图像。所有这些图像都是通过Parse api在后台加载的。我正在运行Instrument的分配和匿名VM:ImageIO_JPEG_DATA类占用了大部分正在使用的内存。应用程序中的所有内存大约等于40,然后此类别超过55,这使得总数大约为100.该类别永远不会下降,只是保持一致。如何从我的集合视图中的图像中释放这些内存?

I have multiple collection views on screen at one time that scroll horizontally. They are all filled with images. All of these images are being loaded in the background through the Parse api. I am running Instrument's allocations and the anonymous VM: ImageIO_JPEG_DATA category is taking up a majority of the memory being used. All memory in the app equals to about 40 and then this category is over 55, which puts the total right around 100. That category never goes down at all and just stays consistent. What can I do to free up this memory from the images in my collection views?

以下是我的集合视图的代码:

Here is the code for my collection view:

.m用于我的集合视图控制器

.m for my collection view controller

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    CollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"CollectionViewCell" forIndexPath:indexPath];

    if (cell) {
        [cell.loadingImageIndicator setHidden:NO];
        [cell.loadingImageIndicator startAnimating];

        id photo = [self.collectionViewPhotos objectAtIndex:indexPath.item];

        if ([photo isKindOfClass:[PFObject class]]) {
            PFObject *photoObject = (PFObject *)photo;

            PFFile *imageFile = [photoObject objectForKey:kPhotoPictureKey];
            [cell.cellImage setFile:imageFile];

            [cell.cellImage loadInBackground:^(UIImage *image, NSError *error) {
                [cell.cellImage setContentMode:UIViewContentModeScaleAspectFill];
                [cell.loadingImageIndicator stopAnimating];
                [cell.loadingImageIndicator setHidden:YES];
            }];
        } else if ([photo isKindOfClass:[UIImage class]]) {
            [cell.cellImage setImage:photo];
            [cell.cellImage setContentMode:UIViewContentModeScaleAspectFill];
        }
    }

    return cell;
}

.m for CollectionViewCell

.m for CollectionViewCell

- (void)prepareForReuse
{
    self.cellImage.image = nil;
}

- (void)dealloc
{
    self.cellImage = nil;
}

编辑:工具照片

Photo of instruments

推荐答案

我有在照片库类型的应用程序中同样的问题,并在所谓的ImageIO_JPEG_DATA类别中累积并永久保持实时的分配遇到同样的问题,导致我的应用程序内存不足。奇怪的是,这只发生在我正在测试的iPad上而不是在ios模拟器上(没有显示内存问题)。

I had the same issue in a photo gallery-type app, and ran into the same problem with allocations in the so-called ImageIO_JPEG_DATA category accumulating and remaining "live" forever, causing my app to run out of memory. Oddly, this happenned only on the iPad I was testing on and NOT on the ios simulator (which showed no memory problems).

Brian的建议(下面)对我有用。我的应用程序最初使用的是一个数组,其中每个元素都包含一个UIImage。这些图像用于各种UIScrollViewControllers。

Brian's suggestion (below) worked for me. My app was originally using an array, each element of which contained - amongst other things - a UIImage. The images were used in various UIScrollViewControllers.

当我需要加载图像时,如果我使用

When I needed to load an image, if I used

[UIImage imageWithContentsOfFile:path]

[UIImage imageWithContentsOfFile:path]

而不是直接引用我的数组中的UIImage,内存问题(由ImageIO_Malloc正在进行的一些无法解释的缓存引起)消失了,ImageIO_JPEG_DATA分配停止堆积并被释放。

rather than a direct reference to the UIImage in my array, the memory problem (caused by some inexplicable caching that ImageIO_Malloc was doing) was gone and the ImageIO_JPEG_DATA allocations stopped piling up and got released.

在我自己的无数年里,我永远不会想出这个解决方案,所以感谢Brian。

I would never have come up with this solution in a gazillion years on my own, so thanks to Brian.

这篇关于UIImage内存没有解除分配VM:ImageIO_JPEG_DATA?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆