Метод dealloc не вызывается в существующем контроллере модального представления - PullRequest
0 голосов
/ 25 марта 2010

Это в моем представлении контроллер

-(void)doctorsListAction
{
    if(isFirst == YES)
    {
      [self getDoctorsListController];
      [[self navigationController] presentModalViewController:doctorListViewNavigationController animated:YES];
      [doctorListViewController release];
    }       
}

-(void)getDoctorsListController
{
    //DoctorListViewController *doctorListViewController=[[[DoctorListViewController alloc]initWithNibName:nil bundle:nil]autorelease];

    doctorListViewController=[[DoctorListViewController alloc]init];
    doctorListViewNavigationController=[[UINavigationController alloc]initWithRootViewController:doctorListViewController];
    doctorListViewController.doctorList=doctorList;
    doctorListViewNavigationController.navigationBar.barStyle=  UIBarStyleBlackOpaque;
    [doctorListViewController release];
}

Это в DoctorListViewContrller

-(void)closeAction
{
    printf("\n hai i am in close action*******************************");
    //[doctorList release];
    //[myTableView release];
    //myTableView=nil;

    printf("\n myTableView retainCount :%d",[myTableView retainCount]);

    [[self navigationController] dismissModalViewControllerAnimated:YES];


}
//this method is not called I don't know why if it not called i will get memory issues

- (void)dealloc 
{
    printf("\n hai i am in dealloc of Doctor list view contrller");
    [doctorList release];
    [myTableView release];
    myTableView=nil;
    [super dealloc];
}

Ответы [ 2 ]

1 голос
/ 26 марта 2010

этот метод не называется я не знаю почему, если он не называется, я получу память вопросы

Когда точно вызывается dealloc (т. Е. Когда объект освобождается), это не должно иметь для вас никакого значения. Важно то, что вы объединяете каждую alloc с release / autorelease. Что вы, вероятно, не делаете.

Приведенный выше код не очень хорошо читается и выглядит немного "Java" -ish. Ваш метод get на самом деле ничего не возвращает, что выглядит странно. Но в любом случае вы бы не назвали метод "get___".

Вы, вероятно, теряете память в методе getDoctorsListController в этой строке:

doctorListViewNavigationController=[[UINavigationController alloc]initWithRootViewController:doctorListViewController];

Так как вы не определили doctorListViewNavigationController в этом методе, и я предполагаю, что вы разместили код, который компилируется, это либо член (хотя и не обязательно свойство) вашего класса, либо где-то статическая переменная. Это означает, что он уже может указывать на объект. Это означает, что когда вы назначаете новый alloc 'ed объект, старый теряется (протекает).

Вот как вы должны рефакторинг.

- (void)doctorsListAction
{
    if (isFirst == YES)
    {
        [self showDoctorsList];
    }       
}

- (void)showDoctorsList
{
      DoctorListViewController* doctorListViewController = [[DoctorListViewController alloc] initWithNibName:nil bundle:nil];
      doctorListViewController.doctorList = doctorList;
      UINavigationController* navController = [[UINavigationController alloc] initWithRootViewController:doctorListViewController];
      navController.navigationBar.barStyle = UIBarStyleBlackOpaque;
      [self.navigationController presentModalViewController:navController animated:YES];
      [navController release];
      [doctorListViewController release];
}
0 голосов
/ 25 марта 2010

Там может быть много других объектов "за сценой", которые хотят держать вокруг DoctorListViewController. Если вы просто уравновешиваете свои удержания и выпуски, вы должны быть в порядке.

Также в -(void)doctorsListAction, не должно ли [doctorListViewController release]; быть [doctorListViewNavigationController release]; вместо?

...