objective c - iOS UICollectionView memory leak -


i've created uicollectionview through storyboard. cell custom cell class have 3 buttons images. images available part of class galleryiteminfo. have array of objects

[gallerydataprovider sharedinstance].iteminfo 

there code cellforitematindexpath (in 1 cell there 3 buttons 3 items in array):

- (uicollectionviewcell *)collectionview:(uicollectionview *)collectionview cellforitematindexpath:(nsindexpath *)indexpath {     collectionviewcellpreviewtriple *cell;      if (indexpath.row % 2 == 0 && !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 < [[gallerydataprovider sharedinstance].iteminfo count])         image2 = ((galleryiteminfo *)[[gallerydataprovider sharedinstance].iteminfo objectatindex:leftpreviedid + 1]).slotpreviewimage;      if (leftpreviedid + 2 < [[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; } 

trouble: when scroll collection memory usage increases every swipe right left on 1 megabyte.

why memory not released?

update:

collectionviewcellpreviewtriple code (created through storyboard):

#import <uikit/uikit.h>  @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<uicollectionviewpreviewcelldelegate> 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 

update:

- (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)];     //} } 

profiling link screen

this may related issue many people have been suffering cell's not reused.

to test this, should override method prepareforreuse , in write simple log:

nslog(@"%@ being called expected.", nsstringfromselector(_cmd)); 

you should run app, scroll collection view, , check console see if log appears.

if log not appear, may want check answer how proceed. in app cells not reused in simulator, reused on devices. it's odd.


Comments

Popular posts from this blog

java - Intellij Synchronizing output directories .. -

git - Initial Commit: "fatal: could not create leading directories of ..." -