简体   繁体   中英

Programmatic custom cell memory leak issue

I have recently switched to "Programming Without XIB's" and facing an issue with Custom TableView cells. Previously when using XIB, I used the following code which worked perfectly,

NSString *CellIdentifier = @"Cell";
AttachmentCustomCell *cell=(AttachmentCustomCell*)[self.attachmenttableview dequeueReusableCellWithIdentifier:CellIdentifier];
if(cell==nil){
    NSArray* objects= [[NSBundle mainBundle] loadNibNamed:@"AttachmentCustomCell" owner:nil options:nil];
    AttachmentCustomCell *acell = [objects objectAtIndex:0];
    cell = acell;
}

but now I am using the following,which gives me a memory leak,

    static NSString *CellIdentifier = @"Cell";
ConditionReportCustomCell *cell = (ConditionReportCustomCell*)[self.inventoryTableView dequeueReusableCellWithIdentifier:CellIdentifier];
if(cell==nil){
    cell = [[ConditionReportCustomCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] ;
}
return cell;

Please tell me what I am doing wrong. I know I cant use autorelease as it results in crashing of the application.

如果您不使用ARC,只需添加自动释放:

cell = [[[ConditionReportCustomCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease] ;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM