应用由于内存压力而终止

时间:2015-09-24 10:31:09

标签: ios memory memory-leaks crash uiimage

我的应用程序在iPhone4上崩溃,经常使用5到10分钟。

我在应用程序本身有一些图像,有内部SQLite文件,图像名称存储在sqlite表中并从名称中使用。

还通过网址(NSURL)从在线数据库中获取一些图像。使用SDWebImage框架在UIImageView中加载在线数据库映像。但仍然得到"收到内存警告"和应用程序被终止

我已经检查了仪器,它显示图像获取更多数据并导致崩溃

从DB获取图像数组并将图像加载到UICollectionViewCell中的UIImageView

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *identifier = @"Cell";
UICollectionViewCell *cell1 = [self->collectionView dequeueReusableCellWithReuseIdentifier:@"cell1" forIndexPath:indexPath];
for (UIImageView *lbl in cell1.contentView.subviews)
    {
        if ([lbl isKindOfClass:[UIImageView class]])
        {
            [lbl removeFromSuperview];
        }
    }
imgView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, cell1.frame.size.width, cell1.frame.size.width)];
    imgView.backgroundColor = CLEAR_COLOR;
    imgView.contentMode = UIViewContentModeScaleAspectFit;
    UIImage *imv = [UIImage imageNamed:(NSString *)mArray_FeatIcon[indexPath.item]];
    imgView.image = imv; 
    [cell1.contentView addSubview:imgView];
    imv = nil;
return cell1;
}

从UICollectionView中的weburl加载图像

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    UICollectionViewCell *cell1 = [cvGallery dequeueReusableCellWithReuseIdentifier:@"cell1" forIndexPath:indexPath];
    for (UIImageView *lbl in cell1.contentView.subviews)
    {
        if ([lbl isKindOfClass:[UIImageView class]])
        {
            [lbl removeFromSuperview];
        }
    }
    UIImageView * imgView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, cell1.frame.size.width, cell1.frame.size.height)];
    imgView.backgroundColor = [UIColor clearColor];

    NSString *urlString = [[NSString stringWithFormat:@"%@",mArrThumbUrl[indexPath.item]] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    [imgView setImageWithURL:[NSURL URLWithString:urlString] placeholderImage:[UIImage imageNamed:@"logo.png"]];
    [cell1.contentView addSubview:imgView];
    return cell1;
} 

由于声誉低,无法添加乐器的屏幕截图。提前谢谢。

1 个答案:

答案 0 :(得分:0)

可能是因为iPhone中的内存管理泄漏。请参阅本教程链接并检查仪器中的NSZombies。

点击此链接 - >我认为这非常有用。

http://www.raywenderlich.com/23037/how-to-use-instruments-in-xcode

相关问题