title: Terminating due to Memory pressure
body: <p>I have a collection view, which loads images from documents directory. When I try to laod these images to the collectionview, the app get crashed with a memory warning. </p>
  
  <pre><code>-(UICollectionViewCell*)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
  {
  UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"Cell" forIndexPath:indexPath];
  UIImage *cellImage;
  if (indexPath.section == 0) {
  
      NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
      NSString *documentsDirectoryPath = [paths objectAtIndex:0];
      NSString *folderPath = [documentsDirectoryPath  stringByAppendingPathComponent:@"Photos"];  // subDirectory
      NSString *filePath;    
      if ([[NSFileManager defaultManager] fileExistsAtPath:folderPath])
          filePath = [folderPath stringByAppendingPathComponent:[NSString stringWithFormat:@"Photo%d",indexpath.row]];
  
      cellImage = [UIImage imageWithContentsOfFile:filePath];
  
  } else if (indexPath.section == 1){
      cellImage = [UIImage imageNamed:@"btn_vid.png"];
  } else if (indexPath.section == 2){
      cellImage = [UIImage imageNamed:@"btn_mic.png"];
  } else if (indexPath.section == 3){
      cellImage = [UIImage imageNamed:@"btn_1.png"];
  }
  UIImageView *imageView = (UIImageView *)[cell viewWithTag:100];
  [imageView setImage:cellImage];
  
  return cell;
  }
  </code></pre>
  
  <p>What am I doing wrong?</p>
  
  <p>Update: <img src="https://stackoverflow.com/users/18017/airsource-ltd" alt="enter image description here"></p>
  
  <p>The images are good sized because I take it from the phone's camera and save in documents directory</p>
  
  <p><strong>UPDATE:</strong></p>
  
  <p>I have received the suggestion of adding thumnails for the images and then load them from <a href="https://stackoverflow.com/users/18017/airsource-ltd">Airsource Ltd</a>. I used this code to generate the thumbnail images instead of his and it worked. But I would like to know, which one is better. </p>
  
  <pre><code>+(UIImage*) generateThumbnailFromImage:(UIImage*)theImage
  {
  UIImage * thumbnail;
  CGSize destinationSize = CGSizeMake(80,80);
  
  UIGraphicsBeginImageContext(destinationSize);
  [theImage drawInRect:CGRectMake(0,0,destinationSize.width, destinationSize.height)];
  thumbnail = UIGraphicsGetImageFromCurrentImageContext();
  UIGraphicsEndImageContext();
  
  return thumbnail;
  }
  </code></pre>