【发布时间】:2015-03-17 21:31:11
【问题描述】:
PFImages 的自定义集合视图占用过多内存时遇到问题。在 Parse 中,我只有 7 个对象,但在加载集合视图时内存达到了 1.1 GB。此外,离开视图时内存不会释放。
这是我的代码
自定义单元格
- (id)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {
[self setup];
}
return self;
}
- (id)initWithCoder:(NSCoder *)anotherDecoder {
self = [super initWithCoder:anotherDecoder];
if (self) {
[self setup];
}
return self;
}
- (void)setup {
self.pictureImageView = [[PFImageView alloc]init];
self.pictureImageView.frame = CGRectMake(0, 0, self.pictureView.frame.size.width, self.pictureView.frame.size.height);
[self.contentView addSubview:pictureImageView];
}
收藏查看代码
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
PicturesCollectionViewCell *cell = (PicturesCollectionViewCell *) [collectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath];
tempObject = [picturesArray objectAtIndex:indexPath.row];
PFFile *file = [tempObject objectForKey:@"thumbnail"];
cell.pictureImageView.file = file;
cell.pictureImageView.image = [UIImage imageNamed: @"LOADING.png"];
[cell.pictureImageView loadInBackground];
cell.pictureImageView.contentMode = UIViewContentModeScaleAspectFill;
cell.titleLabel.text = [tempObject objectForKey:@"title"];
NSLog(@"Image: %@, File: %@, at index: %li", cell.pictureImageView.image, cell.pictureImageView.file, indexPath.row);
return cell;
}
【问题讨论】:
-
PFImageView 有开源代码,我认为他们在那里使用 NSCache 会在内存警告时自行清除。
标签: ios objective-c memory parse-platform uicollectionview