Ios 对象创建和释放不起作用?

Ios 对象创建和释放不起作用?,ios,objective-c,memory-management,Ios,Objective C,Memory Management,我创建了ViewController。这里有两个按钮正在创建和释放NSObject // This Button for creating & assign the values to the NSObject. - (IBAction)CreateObjectBtn:(id)sender { [cpFileObject methodForRetain]; // Here the tempFilePath = [[NSBundle mainBundle]pathF

我创建了ViewController。这里有两个按钮正在创建和释放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名称-CPFile

问题发生在创建和发布过程中,它只工作了两三次。在单击CreateObjectBtn之后。错误如下所示


如果您在中从Viewcontroller2看到您的队列

[Viewcontroller2 playBtn:]

您正在尝试设置FileDataSetting属性

只要试着记录你正在设置的值和文件数据

if (!fileData) 
{
     [fileData retain];
}  
没有什么可以保留的

您应该首先创建一个对象。您的[fileData retain]应替换为:

if (!fileData) 
{
     fileData =[[NSData alloc] initWithContentsOfFile:tempFilePath];
}
试试这个:

    - (IBAction)CreateObjectBtn:(id)sender 
    {
        cpFileObject.fileData =[NSData dataWithContentsOfFile:tempFilePath];
        cpFileObject.filePath = tempFilePath; 
        [cpFileObject methodForRetain];  //move it down
    }

    -(void)methodForRetain
    {
        [fileData retain]; //it doesn't matter if fileData is nil; 
    }

你能插入你的密码吗。我可以粘贴在这里吗@bsarr007..我已经粘贴了我的代码。请验证并告诉我。如果要释放自动释放对象,请执行以下操作:cpFileObject.fileData=[[NSData alloc]initWithContentsOfFile:tempFilePath];仅仅理解指针是什么就够麻烦的了。使用ARC,您不需要执行保留/释放操作。Am尝试NSData正在打印..但第二次按playBtn时:出现错误访问。您在该属性中设置了什么?我们正在将歌曲数据设置到该属性@rajeshyou尝试记录tht数据?我的问题是你的数据正确吗?在我的一个项目中,我遇到了这样的问题。我绞尽脑汁才发现问题所在,问题是一个数组保存了自身的引用。如果我这样做,同样的问题也会发生。
    - (IBAction)CreateObjectBtn:(id)sender 
    {
        cpFileObject.fileData =[NSData dataWithContentsOfFile:tempFilePath];
        cpFileObject.filePath = tempFilePath; 
        [cpFileObject methodForRetain];  //move it down
    }

    -(void)methodForRetain
    {
        [fileData retain]; //it doesn't matter if fileData is nil; 
    }