开发者

What could be happened if at a dismissModalViewController call doesn't follow up a dealloc call?

I have a strange problem. I set up a simple system that present modally a view. When i call dismiss for this modal view, the view disappear correctly but neither dealloc or viewDidUnload calls are done.

Here the code to make the view appear:

开发者_C百科
-(IBAction) spendBtnTap{
    SpendVC *spendVC = [[SpendVC alloc] initSpendWithContext:self.context]; 
    spendVC.delegate = self;
    [self presentModalViewController:spendVC animated:YES];
    [spendVC release];
} 

And the code to make the view disappear (from SpendVC.m):

-(void) pressBackBtn{   
    [self.delegate dismissModalViewControllerAnimated:YES];
}

And for dealloc in SpendVC ... i just added this output (But nothing happen in my console log...):

- (void)dealloc {
    NSLog(@"spend dealloc");
}

In my application i have other button set this way... and they work correctly ... what can i missed?


From the UIViewController docs:

viewDidUnload is called during low-memory conditions when the view controller needs to release its view and any objects associated with that view to free up memory

So it's not likely to be called.

As for dealloc, is something else retaining SpendVC?


Just to know,

I encountered a similar problem the last week. On my last project i found that the -(void)dealloc method was not called after the dismissModalViewControllerAnimated: message.

I was in stuck for some hours and then i found the solution. In my case, the problem was due to a scheduledTimer that i triggered somewhere in the viewcontroller.

Be sure to disable all timers before calling dismissModalViewControllerAnimated:. I solved as follow:

- (void)doneDidPressed {
    if(startTimer) {
        [startTimer invalidate];
        [startTimer release];
        startTimer = nil;
    }
    [self dismissModalViewControllerAnimated:YES];
}


I just added another test in disappear function (that is correctly called) to check retain count with :

NSLog(@"%d",[self retainCount]); 

It returns 2 ..

I found that in viewDidLoad of SpendVC if i remove this code the retain is correctly set to 1 and after dismiss dealloc is call correctly.

//Setup category list
self.cats = [[CatSelectVC alloc]initWithContext:self.context];
self.cats.delegate = self;
self.cats.view.center = CGPointMake(160, 160);
[self.view addSubview:self.cats.view];

where is incremented the retain in this code ? self.cats.delegate = self ? in this case what i have to do to release all correctly ?

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜