tags:

views:

19

answers:

2

I've struggled to get a login / startup view to show before my mainWindow nav controllers and its finally working, but I'm now getting these analyzer warnings. If I release the navigation controller, the release in the dismiss button with cause an error.

what should I do here ?

alt text

+1  A: 

You get a warning, because you allocate a new object, but your reference is lost when the method returns. You probably want to make your lvc an instance variable, so that you can access it later (and maybe release it when it's no longer needed).

Eiko
Thanks, so declare it in my h file interface AND add release it in dealloc ? If I release it in dealloc and its already released in from a dismiss close button, won't that cause an error?
Jules
You could set it to nil when releasing it, so the next release is harmless.
Eiko
So release it then set it to nil in my dismiss button ?
Jules
Actually I'm not releasing it in my dismiss buttons, I do the same thing with different views. if (helpPage != HelpPageGettingStarted) { [self dismissModalViewControllerAnimated:YES]; } else { [self.view removeFromSuperview]; }
Jules
Maybe I don't need to release at all or set to nil ??? or do I, if I do release then nil ?
Jules
Yes - that should do the trick. Although keeping the reference around seems unnecessary it seems like an "ok" approach. View controllers can be a bit troublesome with memory-management compared to plain views - views are easy to create, add as subviews and can be released; but the controllers in many cases cannot (with many exceptions of course).
Eiko
Problem is you are adding its view (which will be retained by the window), but nothing retains your controller (except yourself by allocating it) - so it is up to you to release it when you're done with it. And releasing it in the didFinishLaunching...: method is too early as you will need it around later. Releasing it after closing would be my first try here, i.e. when you remove the view and replace it with something else.
Eiko
It seems ok, just releasing in delegate dealloc, with nothing extra (aka nil, releasing, anywhere else), no crashes or anything in analyzer, so you think i'm ok as is ?
Jules
Technically yes, but you keep the view controller alive until the end of the program, which is probably not what you want. Will it hurt? Unlikely. :-)
Eiko
A: 

What you are doing isn't incorrect as such, and this is just a warning. You need to release the view and controller from wherever you are dismissing the login view.

calmh