views:

47

answers:

2

Does UINavigationBar retain nav items pushed onto its stack? In other words, after doing this:

_myNavItem = [[UINavigationItem alloc]initWithTitle:@"Home"];
[self.navBar pushNavigationItem:_myNavItem animated:NO];

do I need to release _myNavItem with:

    [_myNavItem release];

in order to avoid a memory leak?

Also, how do I find out in general whether or not an object will be retained? Is it just a convention that any Objective C collection maintains ownership of all elements added to it?

+2  A: 

Yes, the UINavigationBar retains its UINavigationItems. Just like an NSArray or NSDictionary retains its objects, so does a UINavigationBar.

Jacob Relkin
Is there anywhere in the apple docs that states this, or is it just a general convention? I'm not doubting your answer, just wondering how I can find this out myself next time rather than asking SO :)
Pete Hodgson
+2  A: 

The ADC UINavigationBar Class Reference mentions at the definition of the items property it is storing all UIViewControllers pushed onto the navigation stack with an NSArray.

Moving on to the NSArray Class Reference, it is stated that the default implementation of the NSArray class retains every object inserted into it and releases it when it is removed.

Putting these two things together it is safe to imply that UINavigationController retains all of its UIViewControllers when they are pushed onto the stack.

Denis 'Alpheus' Čahuk