有一個小問題,此代碼:問題的一個潛在的泄漏
UITableViewCell *cell = (UITableViewCell *)[[button superview] superview];
[button setBackgroundImage: [UIImage imageNamed:@"blueButton.png"] forState:UIControlStateNormal];
VersionsPopover* content = [[[VersionsPopover alloc] initwithChapter:button.chapter]autorelease];
UIPopoverController* aPopover = [[UIPopoverController alloc] initWithContentViewController:content];
aPopover.delegate = self;
aPopover.popoverContentSize = CGSizeMake(500,[self filesFromFolderWithChapter:button.chapter] * 60);
這
VersionsPopover* content = [[[VersionsPopover alloc] initwithChapter:button.chapter]autorelease];
總是讓我潛在的泄漏。
與autorelease
我收到aPopover
「對象發送過多次autorelease」。
當我使用[content release]
Xcode告訴我,我不擁有這個對象。
沒有發佈它說「潛在的泄漏」。
不知道還有什麼我可以嘗試解決這個...
爲什麼在初始化時發送'retain'消息?保留計數應該是2 ...並且'aPopover'也應該保留它。我認爲沒有'autorelease'消息和一個最終'發佈'應該沒問題。 – 2011-07-07 10:20:42
雅文斯,你是對的......但我們不知道代碼中究竟發生了什麼。由於madmax提到,「當我使用[內容發佈]時,Xcode告訴我,我不擁有這個對象,爲了取得對象的所有權,我建議保留這個。 – Ilanchezhian
好吧,我用保留,但現在它說aPopover是一個潛在的泄漏。 ;-)不要明白,因爲我釋放它。 – madmax