2011-11-01 53 views
0

我創建的UITabBarController編程,這樣我的內存泄露了嗎?

mTabBarController = [[UITabBarController alloc] init]; 
... 
NSLog(@"The ref count is : %d", [tabBarItems retainCount]); 
mTabBarController.viewControllers = tabBarItems; 
NSLog(@"The ref count is : %d", [tabBarItems retainCount]); 
[tabBarItems release]; 
NSLog(@"The ref count is : %d", [tabBarItems retainCount]); 

此外,在dealloc中釋放mTabBarController,這樣,

- (void)dealloc { 
    [mTabBarController release]; 
    ... 
} 

現在的問題:輸出的第一代碼片段是

2011-11-01 17:48:26.554 PostCardPrinter[12176:207] The ref count is : 1 
2011-11-01 17:48:26.561 PostCardPrinter[12176:207] The ref count is : 1 
2011-11-01 17:48:26.561 PostCardPrinter[12176:207] The ref count is : 1 

我得到內存泄漏?爲什麼總是打印1?

如果它保留tabBarItems則第二輸出應爲2。如果

mTabBarController.viewControllers = tabBarItems; 

拷貝數組項並保留每個各數組項然後,該第三輸出應該B 2嗎?

我有什麼問題嗎?

+3

讓retainCount咆哮開始吧! - 編輯:發現它http://stackoverflow.com/questions/4636146/when-to-use-retaincount – Joe

+0

:)讓它開始... – deimus

+0

好吧,因爲我是新的iOS開發,我真的需要你的評論;)順便說一句,你最好寫一個答案比評論... – deimus

回答