Question

My view controller I represent modally never get reallocates it is always living (saw by count in instruments).

I saw similar questions on this site, the answers were "you should find what strong object is pointing to the modal view controller"

I cannot find it out, please help me here is my code:

here I call for modal view:

 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [self dismissKeyboard];
    [self CheckAndStore:indexPath.row];
    NSLog(@"At Select");
    self->DetailsView = [[InfoViewController alloc]initWithParameter:[PersonsFromSearch objectAtIndex:indexPath.row]];
    DetailsView.delegate = self;
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    [self presentViewController:DetailsView animated:YES completion:nil];
}

here inside modal view:

-(void) Back
{
     NSLog(@"Back Clicked");
     [self dismissViewControllerAnimated:NO completion:nil];
}

initWithParameter:

- (id) initWithParameter:(id)parameter
{
    Dict = parameter;
    return self;
}

inside detailsView.h

     @interface InfoViewController : UIViewController <UITableViewDelegate,     UITableViewDataSource , UISearchBarDelegate
,MFMessageComposeViewControllerDelegate,MFMailComposeViewControllerDelegate>
    {
        id<InfoViewControllerDelegate> __weak delegate;
        NSDictionary *Dict;
        …
    }
    @property (weak, nonatomic) id <InfoViewControllerDelegate> delegate; 
    ...

DetailsView is an iVar (could it be a problem ?)

If need more code please tell me I will post (I am quite newbie in iOS development).

Was it helpful?

Solution

You should declare your delegate in DetailsView to be weak to avoid strong reference cycle. Also you need to set your self->DetailsView to nil when you want to release it. Because if you still hold a strong reference to it, how could it be deallocated?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top