【发布时间】:2014-06-27 18:56:08
【问题描述】:
我一次在屏幕上有多个水平滚动的集合视图。它们都充满了图像。所有这些图像都通过 Parse api 在后台加载。我正在运行 Instrument 的分配和匿名 VM:ImageIO_JPEG_DATA 类别占用了大部分正在使用的内存。应用程序中的所有内存大约等于 40,然后这个类别超过 55,这使总数大约为 100。那个类别根本不会下降,只是保持一致。我可以做些什么来从我的收藏视图中的图像中释放这些内存?
这是我的收藏视图的代码:
.m 用于我的集合视图控制器
- (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
- (void)prepareForReuse
{
self.cellImage.image = nil;
}
- (void)dealloc
{
self.cellImage = nil;
}
编辑:乐器照片
【问题讨论】:
-
你解决过这个问题吗?我有一个非常相似的问题。 stackoverflow.com/questions/25633253/…
标签: ios objective-c memory uicollectionview