0
votes

My application getting crashed on iPhone4 for frequent use of 5 to 10 mins.

I having some images in application itself , have internal SQLite file, image names are stored in sqlite table and used from the name.

Also fetch some images from online DB via url (NSURL). Online DB images are loaded in UIImageView using SDWebImage framework. But still am getting "Received memory warning" and app getting terminated

I have checked with instruments its shows the image getting more data and lead to crash

getting array of images name from DB and loading image to UIImageView present in UICollectionViewCell

- (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;
}

image loading from weburl in UICollectionView

- (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;
} 

Not able to add screen shot of instruments, because of low reputation. Thanks in advance.

1
Hello, welcome to SO. Could you please attach some logs that may tell us better where the problem might be? - Erveron
@James, am getting the log as "Received memory warning". It arrives upto 4 times then app getting crash. And get alert in Xcode -> App terminated : due to memory pressure - Rajendran Balakrishnan

1 Answers

0
votes

May be this is due to leakage of memory management in iPhone. Please refer this tutorial link and check for NSZombies in Instruments .

Follow this link-> I think this is very useful.

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