2010-04-14 147 views
0

我想呈現一個模態視圖控制器。我已閱讀文檔,但有些奇怪。這裏是我的代碼:Presentmodalviewcontroller方法問題與保留計數

NSLog(@"rc: %d", [modalViewController retainCount]); 
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:modalViewController]; 
[self presentModalViewController:navigationController animated:YES]; 
[navigationController release]; 
NSLog(@"rc: %d", [modalViewController retainCount]); 

並在控制檯上出現:

RC:2
RC:24

而且我覺得24是很奇怪......你這是什麼瘦?這是爲什麼發生?

+0

我不知道你的具體問題,但 - [NSObject retainCount]返回一個NSUInteger,所以你應該在格式字符串中使用%u,而不是%d。 – 2010-04-14 10:02:04

+0

好的,我已改爲%u。一樣的。 – 2010-04-14 10:04:11

回答

2

你不應該擔心保留計數的價值太多。使用這種系統調用時,可能會發生任何數量的保留/釋放循環。

如果您的視圖控制器正確呈現模式,那麼有什麼問題?

+0

在關閉我的ModalViewController後出現內存泄漏,我無法找到泄漏的位置。 :( – 2010-04-14 10:07:32

+0

這不是在這個代碼中。modalViewController創建在哪裏? – Jasarien 2010-04-14 10:40:35

+0

好吧,我發現它。我設置了這樣的屬性:self.prop = [data retain]; 我現在很生氣... – 2010-04-14 10:45:16