[問題] retain count的問題
我有一個tableViewController,然後我在leftBarButtonItem上加了個Button
這個button被clicked以後就會觸發下列method
- (void)addPost:(id)sender {
PostViewController *postViewController = [[PostViewController alloc]
initWithUserID:userID];
postViewController.delegate = self;
UINavigationController *postNavigationController =
[[UINavigationController alloc]
initWithRootViewController:postViewController];
[self.tabBarController presentModalViewController:postNavigationController animated:YES];
[postViewController release];
[postNavigationController release];
}
<我遇到的第一個問題是>
每當我dismissModalViewController (也就是上述的postViewController)後
console就出現 EXEC_BAD_ACCESS
如果我comment最後兩行code中任一行,
(也就是[postViewController release] or [postNavigationController release])
就不會出現 EXEC_BAD_ACCESS
所以我就想看看retain count到底是多少
於是我就加入了一些NSLog
- (void)addPost:(id)sender {
PostViewController *postViewController = [[PostViewController alloc]
initWithUserID:userID];
NSLog(@"retain count = %d", [postViewController retainCount]);
postViewController.delegate = self;
NSLog(@"retain count = %d", [postViewController retainCount]);
UINavigationController *postNavigationController =
[[UINavigationController alloc]
initWithRootViewController:postViewController];
NSLog(@"retain count = %d", [postViewController retainCount]);
NSLog(@"postNavigationController retain count = %d",
[postViewController retainCount]);
[self.tabBarController presentModalViewController:postNavigationController animated:YES];
NSLog(@"retain count = %d", [postViewController retainCount]);
NSLog(@"postNavigationController retain count = %d",
[postViewController retainCount]);
[postViewController release];
NSLog(@"retain count = %d", [postViewController retainCount]);
NSLog(@"postNavigationController retain count = %d",
[postViewController retainCount]);
//[postNavigationController release];
}
沒想到結果竟然是
2010-09-28 10:02:29.630 postViewController retain count = 1
2010-09-28 10:02:29.630 postViewController retain count = 1
2010-09-28 10:02:29.631 postViewController retain count = 3
2010-09-28 10:02:29.632 postNavigationController retain count = 3
2010-09-28 10:02:29.690 postViewController retain count = 26
2010-09-28 10:02:29.690 postNavigationController retain count = 26
2010-09-28 10:02:29.691 postViewController retain count = 25
2010-09-28 10:02:29.691 postNavigationController retain count = 25
怎麼會跳到26這麼多啊@@
我看到都傻了.....
只好把問題放上來問問有沒有一點提示了QQ
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 114.136.207.246
→
09/28 10:39, , 1F
09/28 10:39, 1F
→
09/28 10:39, , 2F
09/28 10:39, 2F
→
09/28 10:40, , 3F
09/28 10:40, 3F
→
09/28 10:40, , 4F
09/28 10:40, 4F
→
09/28 15:45, , 5F
09/28 15:45, 5F
→
09/28 17:07, , 6F
09/28 17:07, 6F
MacDev 近期熱門文章
PTT數位生活區 即時熱門文章