5
Xcode中的泄漏工具在這裏顯示了內存泄漏。我已經評論了Leaks抱怨的受影響行。但我看到我的內存管理沒有錯誤...這段代碼爲什麼會產生內存泄漏?
- (void)setupViewController {
MyViewController *myVC = [[MyViewController alloc] init];
UITabBarItem *tbi = [[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemDownloads tag:1];
myVC.tabBarItem = tbi; // LEAK: 128 bytes
self.myViewController = myVC;
[myVC release];
[tbi release];
}
我的意思是... tbi和myVC是在最後發佈,並且alloc是平衡的。那麼,怎麼了?我不明白。
myVC的tabbar屬性應該是一個定義要保留的屬性。如果這樣做,分配給該屬性的對象的保留將自動保留。 – TechZen 2010-02-15 20:57:55
好了,但tabBarItem是來自Apple,而不是我;-)我沒有爲我的View Controller創建任何tabBarItem屬性。 Apple做到了。如果我手動發佈myVC.tabBarItem是因爲Apple已經忘記這麼做,是不是會違反內存管理規則? – dontWatchMyProfile 2010-02-15 21:40:53
'tabBarItem'是具有'retain'語義的屬性。二傳手的泄漏不太可能。 – 2010-07-10 13:54:17