Objective c 目标c访问解除分配的对象

Objective c 目标c访问解除分配的对象,objective-c,nullpointerexception,crash,exc-bad-access,Objective C,Nullpointerexception,Crash,Exc Bad Access,如果执行以下代码,会发生什么情况 NSData* data = [myArray objectAtIndex:i] // assigning from array [myArray removeAllObjects]; // removing all objects from array. [self doSomething:data]; // this method will execute some operations with data 数据是否转化为可能导致EXC\u BAD\u访

如果执行以下代码,会发生什么情况

NSData* data =  [myArray objectAtIndex:i] // assigning from array
[myArray removeAllObjects]; // removing all objects from array.
[self doSomething:data]; // this method will execute some operations with data

数据是否转化为可能导致EXC\u BAD\u访问崩溃的僵尸对象?

不,它不会导致崩溃。您的
数据
只是一个指针,它持有存储NSData数据的相同数字(虚拟)内存地址。如果其中一个指针被设置为指向nil,或指向其他相关数据,则不会触发NSData或其他指针的任何更改。

您是对的。我认为,从可变数组中删除所有对象将取消分配所有分配的内存,但这只会减少数组中每个对象的保留计数。谢谢