我一次在屏幕上有多个水平滚动的集合视图.他们都充满了图像.所有这些图像都是通过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;
}
Run Code Online (Sandbox Code Playgroud)
.m for CollectionViewCell
- (void)prepareForReuse …Run Code Online (Sandbox Code Playgroud)