Krish
Krish

Reputation: 4232

App crash while downloading large images using SDWebImage

I'm using SDWebImage to download image async from server.Some images on server are of size( 1772x1476 pixels.)I'm showing these images on UICollectionView. I'm getting memory warning and app crashes after several run.Some times it happens when images downloaded first time and some time when i scroll the collection view up and down. Here is my code-

i am getting warning on my x code like below image

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{

    UICollectionViewCell *cell=[collectionView dequeueReusableCellWithReuseIdentifier:@"cellIdentifier" forIndexPath:indexPath];

[Mainimage sd_setImageWithURL:[NSURL URLWithString: Obj.imageYH] placeholderImage:[UIImage imageNamed:@""]];

   return cell;
}

enter image description here

Upvotes: 0

Views: 1104

Answers (3)

You can use :

[SDImageCache sharedImageCache].config.shouldDecompressImages = NO; [[SDWebImageDownloader sharedDownloader] setShouldDecompressImages:NO];

In version 4.0-beta

Upvotes: 1

Shreyank
Shreyank

Reputation: 1549

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{

            UICollectionViewCell *cell=[collectionView dequeueReusableCellWithReuseIdentifier:@"cellIdentifier" forIndexPath:indexPath];

    [Mainimage setImageWithURL:[NSURL URLWithString: Obj.imageYH] placeholderImage:[UIImage imageNamed:@""]];

           return cell; 
}        

Try this

Upvotes: 0

Ruchira Randana
Ruchira Randana

Reputation: 4179

If your app doesn't need to show a full sized image, then it's always a good practice to scale it down and then show. Here's an example of what to do.

SDWebImageManager *manager = [SDWebImageManager sharedManager];
[manager downloadWithURL:url delegate:self options:0 success:^(UIImage *image) 
{
    //Scale down the image here and then set to your view.
}

It should help you reduce the memory issues.

Upvotes: 0

Related Questions