So yes, I'm the Java guy in this crazy iPhone world. When it comes to memory management, I donβt understand very well what I am doing.
I have an application that uses a navigation controller, and when the time comes to switch to the next view, I have a code that looks like this:
UIViewController *myController = [[MyViewController alloc] initWithNibName:@"MyView" bundle:[NSBundle mainBundle]; [[self navigationController] pushViewController:myController animated:YES];
Now according to Apple's basic rule for memory management
You get ownership of an object if you create it using a method whose name starts with "alloc" or "new" or contains "copy" (for example, alloc , newObject or mutableCopy ), or if you send it a retain message. You are responsible for relinquishing ownership of your own facilities using release or autorelease . At any other time, when you receive an object, you should not let it go.
For me, this means that I must let go of myController or give it an autorelease message. But whenever I try to do this, the application unexpectedly crashes when I click and exit the stack.
This did not affect me, but in the Tools application, he claims that I have no memory leaks.
So my question is:
- Am I doing it right?
- Is the navigation controller owned by MyViewController, explaining no memory leak?
- Should I assign myController to an instance variable in my root ViewController? In this case, it would be marked as save, and I would issue the dealloc root method
memory-management iphone cocoa-touch
bpapa
source share