我使用筆尖作爲幾個按鈕的模板。它似乎工作正常,他們每個人都有自己的獨立國家。但是,當我釋放按鈕時,我會在dealloc中崩潰。下面是代碼...未能在多個筆尖加載後發佈
mSoundBtns = new cSoundButton*[mNumSounds];
for(unsigned int i = 0 ; i < mNumSounds; ++i) {
mSoundBtns[i] = nil;
}
for(unsigned int s = 0; s < mNumSounds; ++s) {
[[NSBundle mainBundle] loadNibNamed:@"InstanceSoundButton" owner:self options:nil];
//Auto Loads via Outlet into 'soundNib'
mSoundBtns[s] = soundNib;
soundNib = nil;
uint32 count = mSoundBtns[s].retainCount;
NSLog(@"Last Count: %d", count);
}
for(unsigned int j = 0; j < mNumSounds; ++j) {
[mSoundBtns[j] release]; //**** Crash here on 7th (of 8) release
mSoundBtns[j] = nil;
}
頁眉:
@interface cLocationContext {
...
cSoundButton** mSoundBtns;
IBOutlet cSoundButton* soundNib;
}
@property (nonatomic, assign) IBOutlet cSoundButton* soundNib;
@end
筆尖很簡單,它只是包括父視圖和自定義視圖類型的子視圖。
cSoundButton只是跟蹤名稱和布爾狀態靜音或不靜音。這裏是的dealloc
- (void)dealloc {
delete[] mSoundTag;
// Call the inherited implementation
[super dealloc]; //****Crashes in here
}
崩潰是調用超級的dealloc裏面,UIButton的 - > UIButtonContent的dealloc。我假設我在執行內存管理方面做得很差,例如兩次釋放,但我無法找到位置。
正是我通過多次加載筆尖合法的做法?
** retainCount **沒用。別叫它。 – bbum 2011-05-12 03:54:05