Madan Mohan
Madan Mohan

Reputation: 8810

Is dealloc method called in presentModalViewController when dismiss the controller

here the following code is used to view the present modal view controller.

[[self navigationController] presentModalViewController:doctorListViewNavigationController animated:YES];

the close action is in the next view controller(DoctorListViewController). You can understand by seeing the following code I added now cleary.

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

    }
}

-(void)getDoctorsListController
{
    DoctorListViewController *doctorListViewController=[[DoctorListViewController alloc]init];
    doctorListViewController.doctorList=doctorList;
    doctorListViewNavigationController=[[UINavigationController alloc]initWithRootViewController:doctorListViewController];
    doctorListViewNavigationController.navigationBar.barStyle=  UIBarStyleBlackOpaque;
    [doctorListViewController release];

//code in next DoctorListViewContrller to dismiss the view.
//code for dismiss the ModalViewController.
-(void)closeAction
{
    [[self navigationController] dismissModalViewControllerAnimated:YES];
}

My problem is the dealloc method is not called then I am getting memory issue problems like object allocations, leaks..

- (void)dealloc 
{

    [doctorList release];
    [myTableView release];
    [super dealloc];
}

Upvotes: 1

Views: 2643

Answers (1)

kpower
kpower

Reputation: 3891

Dealloc method is called when object is released same number of times, as it was retained. When you add doctorListView... (let's call it view) to navigationController (let's call it controller), the controller retains the view. And it was also retained during creation. That's why you should release this view twice: one time with dismissModalView... and one with direct release.

I mean something like this:

  [[self navigationController] presentModalViewController:doctorListViewNavigationController animated:YES];
  [doctorListViewNavigationController release];  // first time

...

- (void)closeAction {
  [[self navigationController] dismissModalViewControllerAnimated:YES];
               // second time
}

Upvotes: 2

Related Questions