0
我有一个内存泄漏导致应用程序崩溃。当我在上面评论时,我没有任何内存泄漏。与setImage相关的内存泄漏
myCell.image1.image = image;
了myCell是定制UICollectionViewCell和创建为:
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView
cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
CustomCollectionCell *myCell = [collectionView dequeueReusableCellWithReuseIdentifier:@"project" forIndexPath:indexPath];
NSData *imageData = [NSData dataWithContentsOfFile:_images[row] options:0 error:NULL];
UIImage *image = [UIImage imageWithData:imageData];
myCell.image1.image = image;
return myCell;
}
的图像是大约8 MB和有7个图像。当我打开第四时间,应用程序崩溃(8x7x4> 200 MB)的视图控制器;)
CustomCollectionCell.h
#import <UIKit/UIKit.h>
#import "CellButton.h"
@interface CustomCollectionCell : UICollectionViewCell
@property (strong, nonatomic) IBOutlet UILabel *titlePro;
@property (strong, nonatomic) IBOutlet UILabel *datePro;
@property (strong, nonatomic) IBOutlet UIImageView *image1;
@property (strong, nonatomic) IBOutlet CellButton * button;
@end
CustomCollectionCell.m
#import "CustomCollectionCell.h"
#import "UIView+Themes.h"
@implementation CustomCollectionCell
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
}
return self;
}
@end
我分析和实时字节得到高于200 MB,并且应用程序崩溃没有错误。当我评论myCell.image1.image = image;
。该应用程序不会崩溃。
我正在使用ARC。 你有什么想法吗?
我们需要更多的代码来帮助你。 myCell创建在哪里?它是一个自定义类吗?你如何宣布image1和图像?你在使用ARC吗? – LuisCien
@LuisCien我提出了我的问题,谢谢。 – tchike
你确定这是'image1'的声明吗? IBOutlet不是一种类型。它应该被声明为:'@property(strong,nonatomic)IBOutlet UIImage * image1' – LuisCien