title: iOS UICollectionView memory leak
body: <p>I've created UICollectionView through storyboard.
  My cell is custom cell class that have 3 buttons with images.
  My images are available as part of class GalleryItemInfo. I have an array of those objects</p>
  
  <pre><code>[GalleryDataProvider sharedInstance].itemInfo
  </code></pre>
  
  <p>There is code for cellForItemAtIndexPath (in one cell there are three buttons for three items in array):</p>
  
  <pre><code>- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
  {
      CollectionViewCellPreviewTriple *cell;
  
      if (indexPath.row % 2 == 0 &amp;&amp; !is_iPhone) {
          cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cellOrangeRed" forIndexPath:indexPath];
          if (is_Fingerprint_Version) {
              cell.imageViewRope.image = [UIImage imageNamed:@"image-rope-1.png"];
          }
      } else {
          cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cellGreenBlue" forIndexPath:indexPath];
          if (is_Fingerprint_Version) {
              cell.imageViewRope.image = [UIImage imageNamed:@"image-rope-2.png"];
          }
      }
  
      cell.previewCellDelegate = self;
      cell.tag = indexPath.row;
      NSInteger leftPreviedId = [cell firstPreviewId];
      self.leftPreviewedID = leftPreviedId;
  
      UIImage *image1 = ((GalleryItemInfo *)[[GalleryDataProvider sharedInstance].itemInfo objectAtIndex:leftPreviedId]).slotPreviewImage;
      UIImage *image2;
      UIImage *image3;
  
      if (leftPreviedId + 1 &lt; [[GalleryDataProvider sharedInstance].itemInfo count])
          image2 = ((GalleryItemInfo *)[[GalleryDataProvider sharedInstance].itemInfo objectAtIndex:leftPreviedId + 1]).slotPreviewImage;
  
      if (leftPreviedId + 2 &lt; [[GalleryDataProvider sharedInstance].itemInfo count])
          image3 = ((GalleryItemInfo *)[[GalleryDataProvider sharedInstance].itemInfo objectAtIndex:leftPreviedId + 2]).slotPreviewImage;
  
      [cell setupWithImage1:image1 image2:image2 image3:image3];
  
      if (self.isEditModeEnabled) {
          [cell showRemoveButtons];
      } else {
          [cell hideRemoveButtons];
      }
  
      return cell;
  }
  </code></pre>
  
  <p>Trouble: when I scroll my collection memory usage increases every swipe from right to left on about 1 megabyte.</p>
  
  <p>Why memory is not released?</p>
  
  <p><strong>Update:</strong></p>
  
  <p>CollectionViewCellPreviewTriple code (created through storyboard):</p>
  
  <pre><code>#import &lt;UIKit/UIKit.h&gt;
  
  @protocol UICollectionViewPreviewCellDelegate;
  
  
  @interface CollectionViewCellPreviewTriple : UICollectionViewCell
  
  @property (weak, nonatomic) IBOutlet UIButton *buttonSlot1;
  @property (weak, nonatomic) IBOutlet UIButton *buttonSlot2;
  @property (weak, nonatomic) IBOutlet UIButton *buttonSlot3;
  @property (weak, nonatomic) IBOutlet UIButton *buttonRemove1;
  @property (weak, nonatomic) IBOutlet UIButton *buttonRemove2;
  @property (weak, nonatomic) IBOutlet UIButton *buttonRemove3;
  @property (weak, nonatomic) IBOutlet UIImageView *imageViewRope;
  
  
  @property (nonatomic, weak) id&lt;UICollectionViewPreviewCellDelegate&gt; previewCellDelegate;
  
  - (void)setupWithImage1:(UIImage *)image1 image2:(UIImage *)image2 image3:(UIImage *)image3;
  - (void)showRemoveButtons;
  - (void)hideRemoveButtons;
  
  - (NSInteger)firstPreviewId;
  
  @end
  
  
  @protocol UICollectionViewPreviewCellDelegate
  
  - (void)collectionViewPreviewCell:(CollectionViewCellPreviewTriple *)collectionViewCell didSelectSubitemWithIndex:(NSInteger)subitemIndex;
  - (void)collectionViewPreviewCell:(CollectionViewCellPreviewTriple *)collectionViewCell didEditModeRequestWithStatus:(BOOL)status;
  - (void)collectionViewPreviewCell:(CollectionViewCellPreviewTriple *)collectionViewCell didRemoveRequestWithIndex:(NSInteger)subitemIndex;
  - (void)slotButtonRequestsShadow:(UIButton *)slotButton;
  
  @end
  </code></pre>
  
  <p><strong>Update:</strong></p>
  
  <pre><code>- (void)setupWithImage1:(UIImage *)image1 image2:(UIImage *)image2 image3:(UIImage *)image3
  {
      [self.buttonSlot1 setBackgroundImage:image1 forState:UIControlStateNormal];
      [self.buttonSlot1 setBackgroundImage:image1 forState:UIControlStateHighlighted];
  
      //if (image2) {
      [self.buttonSlot2 setBackgroundImage:image2 forState:UIControlStateNormal];
      [self.buttonSlot2 setBackgroundImage:image2 forState:UIControlStateHighlighted];
      [self.buttonSlot2 setHidden:(image2 == nil)];
      //}
      //if (image3) {
      [self.buttonSlot3 setBackgroundImage:image3 forState:UIControlStateNormal];
      [self.buttonSlot3 setBackgroundImage:image3 forState:UIControlStateHighlighted];
      [self.buttonSlot3 setHidden:(image3 == nil)];
      //}
  }
  </code></pre>
  
  <p><strong>Profiling</strong>
  <a href="http://i.stack.imgur.com/pxR0U.jpg" rel="nofollow">link for screen</a></p>