2

i am using a collection view for photos when tap on any cell then animate image gallery and we can scroll it but after scrolling all images 3 or 4 time app crashes with message "Terminted due to Memorry error".Any one guide me.Thanks in advance.

Ali Raza
  • 2,796
  • 1
  • 20
  • 24
  • 2
    show your -(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath method – Nikita Took Mar 11 '14 at 14:45
  • Based on the limited given info; do you present an `UIScrollView` after cell tap? If so, you need to manage the offscreen images by yourself. – Desdenova Mar 11 '14 at 14:52

1 Answers1

0

A couple of possibilities:

  1. You want to make sure you use images of the appropriate resolution for your collection view cell. Sometimes people will take a high resolution image and show it in a small collection view cell. The problem is that the uncompressed rendition of the high resolution image will be loaded into memory, which can take up an extraordinary amount of memory.

    You may want to make sure that you have images that are resized to a size that is optimized for your collection view cell. For example, using this category you can do:

    cell.imageView.image = [highResolutionImage imageByScalingToSize:CGSizeMake(...) contentMode:UIViewContentModeScaleAspectFill];
    
  2. You want to be very wary about maintaining your own model structures (arrays/dictionaries/etc.) with UIImage objects. It's better to simply maintain a reference to the image as its stored in your persistent storage.

    If you hold the images in any structure for performance reasons, you might want to use a NSCache that is configured to purge itself upon memory pressure (e.g. something like this).

    Also be wary about imageNamed, as that will cache images, too.

Community
  • 1
  • 1
Rob
  • 415,655
  • 72
  • 787
  • 1,044