私は自分のアプリをさかのぼって、すべてのメモリの問題を処理し、メモリ管理について調べてきました。[objectretainCount]を使用してメモリ割り当てを追跡し始めました。私はカウントが本当に奇妙だと思っているので、これは信頼できるのでしょうか?
誰かが次のことを説明できますか?
これはアプリデリゲートであり、空のmainViewControllerは違いがないことを覚えておいてください。initWithRootViewControllerによってカウントが増加していますが、追加する別の方法がわかりません。
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
/* Create the View Controllers */
UIViewController *mainViewControl = [[[MainViewController alloc] init] autorelease];
/* Create the Navigation Controller */
UINavigationController *navigationController = [[[UINavigationController alloc] initWithRootViewController:mainViewControl] autorelease];
NSLog(@"retain count: %i",[mainViewControl retainCount]);
/* Set the toolbar to purple */
navigationController.navigationBar.barStyle = UIBarStyleBlackTranslucent;
navigationController.navigationBar.tintColor = [UIColor colorWithRed:.6 green:.1 blue:.4 alpha:0.4];
navigationController.navigationBar.translucent = YES;
NSLog(@"retain count: %i",[mainViewControl retainCount]);
navigationController.toolbar.barStyle = UIBarStyleBlackTranslucent;
navigationController.toolbar.tintColor = [UIColor colorWithRed:.6 green:.1 blue:.4 alpha:0.4];
navigationController.toolbar.translucent = YES;
[navigationController setNavigationBarHidden:YES animated:NO];
[navigationController setToolbarHidden:YES animated:NO];
NSLog(@"retain count: %i",[mainViewControl retainCount]);
[window addSubview:[navigationController view]];
NSLog(@"retain count: %i",[mainViewControl retainCount]);
そしてこれがログです〜
2011-01-17 19:47:21.278 ANA[5653:207] 3
2011-01-17 19:47:21.282 ANA[5653:207] 4
2011-01-17 19:47:21.286 ANA[5653:207] 7
2011-01-17 19:47:21.287 ANA[5653:207] 12
2011-01-17 19:47:21.301 ANA[5653:207] Load View
これらのプロパティを変更したり、navigationControllerを参照したりすると、保持カウントが急増する理由がわかりません。
自動リリースなしで手動でリリースしましたが、結果は同じです。基本的に私はそれを理解していません、そしてretainCountコマンドが信頼できるかどうか疑問に思います、なぜなら私がこれを理解できないなら、私は他の場所でメモリの問題をデバッグできないと思うからです...