为什么我不能在对象objective-c中使用release

时间:2022-09-07 09:25:04

i can't release objects after using it in objective-c i found error

我在Objective-c中发现错误后无法释放对象

release is unavailable

发布不可用

example ;

例子;

strokes *current = [strokesarray] objectAtIndex:0];

[current release]

last line is error why ?

最后一行是错误的原因?

1 个解决方案

#1


2  

Your problem is this: since you have Automated Reference Counting (ARC) turned on in your project, you cannot call "release" on objects.

您的问题是:由于您在项目中启用了自动引用计数(ARC),因此无法在对象上调用“release”。

And even if you didn't have ARC turned on, that code would not be correct because A), your brackets in "[strokesarray] objectAtIndex:0]" aren't balanced (syntax error) and B) releasing an object stored in an array means your app will crash with an EXEC_BAD_ACCESS error next time you attempt to access that object in the array.

即使您没有打开ARC,该代码也不正确,因为A),“[strokesarray] objectAtIndex:0]中的括号”不平衡(语法错误)和B)释放存储的对象数组意味着下次尝试访问数组中的该对象时,您的应用程序将崩溃并出现EXEC_BAD_ACCESS错误。

#1


2  

Your problem is this: since you have Automated Reference Counting (ARC) turned on in your project, you cannot call "release" on objects.

您的问题是:由于您在项目中启用了自动引用计数(ARC),因此无法在对象上调用“release”。

And even if you didn't have ARC turned on, that code would not be correct because A), your brackets in "[strokesarray] objectAtIndex:0]" aren't balanced (syntax error) and B) releasing an object stored in an array means your app will crash with an EXEC_BAD_ACCESS error next time you attempt to access that object in the array.

即使您没有打开ARC,该代码也不正确,因为A),“[strokesarray] objectAtIndex:0]中的括号”不平衡(语法错误)和B)释放存储的对象数组意味着下次尝试访问数组中的该对象时,您的应用程序将崩溃并出现EXEC_BAD_ACCESS错误。