UINavigationController and UIViewController dealloc

I recently changed my application to use the UINavigationController, I used to use the UINavigationBar with the addition of a cascading subView, which was a bit weak.

I have a problem using memory. The Leaks tool does not detect leaks, but the ViewControllers that I create and add to the UINavigationController are never released. Thus, the memory usage grows every time I create a new VC and then press the back button on the NavigationController.

I just create and add my VC as follows:

DetailViewController* detailViewController = [[DetailViewController alloc] initWithNibName:@"DetailViewController" bundle:nil];
// setups
[self.navigationController pushViewController:detailViewController animated:YES];
[detailViewController release];

An application never passes through the ViewController deallocand methods viewDidUnload. Shouldn't it be called every time I press the back button?

I searched a lot of tutorials and read Apple's memory management, but it says nothing about the VC lifetime in memory when using the NavigationController.

+3
source share
2 answers

Perhaps you are not doing something wrong, and instead you are facing something like this

In a blog post, the question arose whether we needed to manually issue IBOutlets or not. As it turned out, we should. This was reproduced in iOS 3.1.3, but I have not tested it in iOS 4.0 yet.

, . simimlar, dealloc , , , - . , .

Edit:
, ~ 98, , .

2, dealloc , -, .

.

, , :

[NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(updateUI) userInfo:nil repeats:YES]

. , NSTimer target ( ViewController). NSTimer , dealloc , - (NSTimer) . , , NSTimer dealloc, .

2 :
(exsample):

- (void)setTarget:(id)value {
  if (value != target) { 
    [target release];
    target = [value retain];
}

, self.target, . nil, . Apple.

+5

. , , , , . , .

, . , VC.

+2

Source: https://habr.com/ru/post/1754257/


All Articles