开发者

The dealloc method is not called in the present modal view contrller

It is in My view controller

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

-(void)getDoctorsListController
{
    //DoctorListViewController *doctorListViewController=[[[DoctorListViewController alloc]initWithNibName:nil bundle:n开发者_运维百科il]autorelease];

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

It is in 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];
}


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

When exactly dealloc gets called (i.e. when the object is deallocated) shouldn't really matter to you. What matters is that you pair up each alloc with a release/autorelease. Which you are likely not doing.

The above code doesn't read very well and looks a bit "Java"-ish. Your "get" method doesn't actually return anything, which looks strange. But you normally wouldn't name a method "get___" anyway.

You're probably leaking memory in your getDoctorsListController method on this line:

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

Since you didn't define doctorListViewNavigationController in this method, and I assume you posted code that compiles, it is either a member (although not necessarily a property) of your class or a static variable somewhere. Which means it could already be pointing to an object. Which means when you assign a new alloc'ed object to it, the old one is lost (leaked).

Here's how you should refactor it.

- (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];
}


There might be a lot of other objects 'behind the scenes' that want to keep the DoctorListViewController around. If you just balance out your retains and releases, you should be ok.

Also in -(void)doctorsListAction, shouldn't [doctorListViewController release]; be [doctorListViewNavigationController release]; instead?

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜