开发者

iphone: to much memory consumption and leak in case of table view

I am preparing custom cells like this 1) Created a custom cell with Xib 2) since I have to change content of lables in custom cell corresponding to values read from database. I cant reuse same cellIdentifier

static NSString *MyIdentifier = @"MyIdentifier";
MyIdentifier = [NSString stringWithFormat:@"Cell %d",indexPath.row];

NSString *offendersImagePath = [self applicationDocumentsDirectory];

offendersImagePath=[offendersImagePath stringByAppendingPathComponent:@"Images"];


CustomOffendersCell *cell = (CustomOffendersCell *)[tableView dequeueReusableCellWithIdentifier:MyIdentifier];
if(cell == nil) {
    [[NSBundle mainBundle] loadNibNamed:@"CustomOffendersCell" owner:self options:nil];
    cell = aCustomOffendersCell;
    aCustomOffendersCell=nil;
}
    NSMutableArray *tempArray;//=[[NSMutableDictionary alloc] init];

tempArray=[offendersNamesList objectAtIndex:indexPath.row];

the code goes like above when I checked this thing in instruments its showing leak for this line and high memory consumption

[[NSBundle mainBu开发者_Python百科ndle] loadNibNamed:@"CustomOffendersCell" owner:self options:nil];

can you suggest me some way to get rid of this


You should call "release" method for cell like "[aCustomOffendersCell release]". Also you have to release all the data which you have alloc in cell like UILabel, UIImageView, etc... So, when you put it inside the cell, then release these all data.

Hope it will helpful to you. And let me know for more details.


you should call autorelease on aCustomOffendersCell instead of just assigning nil.

aCustomOffendersCell nil;

Use below

 [aCustomOffendersCell autorelease];
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜