开发者

Simple Obj-C Memory Management Question

开发者 https://www.devze.com 2022-12-30 03:24 出处:网络
This is from some sample code from a book // On launch, create a basic window - (void)applicationDidFinishLaunching:(UIApplication *)application {

This is from some sample code from a book

// On launch, create a basic window
- (void)applicationDidFinishLaunching:(UIApplication *)application { 
 UIWindow *window = [[UIWindow alloc] initWithFr开发者_JAVA技巧ame:[[UIScreen mainScreen] bounds]];
 UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:[[HelloController alloc] init]];
 [window addSubview:nav.view];
 [window makeKeyAndVisible];
}

But a release is never called for window nor for nav.

  1. Release should be called since alloc was called, right?
  2. If #1 is right, then I would need to store a reference to each of these in an instance variable in order to release them in the dealloc?

Perhaps I'm wrong all around...


Yes, normally.

However; UIWindow is normally not released, nor is the root navigation controller, as, well, what's the point. They last for the duration of your application.

Also, get a newer book; we use Interface Builder for this stuff now.

0

精彩评论

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

关注公众号