views:

196

answers:

2

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:nil]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];
}
A: 

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?

Rengers
+1  A: 

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];
}
Shaggy Frog
That certainly isn't a property access. Property accesses have to be through explicit message sends or dot-syntax. You can't just write the name of a property and have it access the property.
Chuck
@Chuck edited to reflect your point. Still likely a leak on that line.
Shaggy Frog
Oh, yeah, I agree (I'm the one who upvoted). I just don't want people getting confused about how properties work.
Chuck
No problem, and you're right.
Shaggy Frog
Thanks for your reponse
Madan Mohan