[英]in App Delegate do I need to release my “window” and “navigationController”?
在 App Delegate 中,我是否:
代碼清單
@interface weekendviewerAppDelegate : NSObject <UIApplicationDelegate> {
UIWindow *window;
UINavigationController *navigationController;
}
@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet UINavigationController *navigationController;
@implementation weekendviewerAppDelegate
@synthesize window;
@synthesize navigationController;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
RootViewController *rootViewController = (RootViewController *)[navigationController topViewController];
rootViewController.managedObjectContext = self.managedObjectContext;
self.window.rootViewController = self.navigationController;
// Configure and show the window
[window addSubview:[navigationController view]];
[window makeKeyAndVisible];
return YES;
}
.
.
正如 Bolt 時鍾所評論的,您需要在 appDelegate class 中添加一個 dealloc 方法。
- (void)dealloc {
[navigationController release];
[window release];
[super dealloc];
}
@greg 如果你曾經在applicationDidReceiveMemoryWarning
中發布你的 window 或 navigationController 不要你認為當你的應用程序收到 memory 警告時你的應用程序會崩潰。
正如@Bolt 和@ishu 所說,您只需要在 dealloc 方法中釋放它。
同樣在applicationDidReceiveMemoryWarning
方法中,您可以釋放那些在某個時間點后不會使用的 class 變量,因為釋放它們可能會導致您的應用程序崩潰。
因此,明智地選擇哪些變量並不重要,它們可能會導致您的應用程序崩潰或阻止您的應用程序正常工作。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.