Search code examples
iphoneviewcontrollerdealloc

dealloc of view controller is not called?


i dont know why the dealloc of the viewcontroller is not calling

please see the code snippet.

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];

    SaleItemsVC *itemsObj = [[SaleItemsVC alloc] initWithNibName:@"SaleItemsVC" bundle:nil];
    [self.navigationController pushViewController:itemsObj animated:YES];

    EventSingleEntity *entityobj=(EventSingleEntity*)[arrSales objectAtIndex:indexPath.row];

    itemsObj.eveintEntityRef=entityobj;
    [itemsObj loadProductsOfEventId:entityobj.event_id];
    itemsObj.EventTitle.text=entityobj.name;
    itemsObj.EventEndDate.text=entityobj.end;
    SalesCell *cell=(SalesCell*)[tableView cellForRowAtIndexPath:indexPath];
    itemsObj.eventImage=cell.imgCenter.image;
    [itemsObj release];


}

Solution

  • You create itemsObj, the controller, so the ref count == 1

    You push itemsObj to self.navigationController, refcount == 2

    You release itemsObj ref count == 1

    It should not be released until self.navigationController releases it.