我創建了ViewController.Here兩個按鈕正在創建釋放NSObject的&。對象創建和發佈不起作用?
// This Button for creating & assign the values to the NSObject.
- (IBAction)CreateObjectBtn:(id)sender
{
[cpFileObject methodForRetain];
// Here the tempFilePath = [[NSBundle mainBundle]pathForResource:@"Innum_Enna_Thozha-VmusiQ.Com" ofType:@"mp3"];
cpFileObject.fileData =[NSData dataWithContentsOfFile:tempFilePath];
cpFileObject.filePath = tempFilePath;
}
// This Button for **release** the NSObject from memory Pool.
- (IBAction)releaseObjectBtn:(id)sender
{
[cpFileObject methodForRelease];
}
NSObject Name - CPFile。
// This Instance Method for **Increase** the allocation of NSObject.
-(void)methodForRetain
{
if (!fileData)
{
[fileData retain];
}
}
// This Instance Method for **Decrease** the allocation of NSObject.
- (void)methodForRelease
{
[fileData release];
NSLog(@"%lu Object released ",(unsigned long)self.retainCount);
}
問題發生在創建&釋放工作只有兩三次。之後如果我點擊CreateObjectBtn
。錯誤顯示是這樣的。
你能插入你的代碼你
[fileData retain]
應改爲? – bsarr007雅。我可以在這裏粘貼嗎? @ bsarr007 .. –
我已經粘貼了我的代碼。請驗證並讓我。 –