放在NSArray、NSDictionary等容器内的对象Item,Item中的property在程序运行过程中被无故释放

时间:2023-03-09 18:08:46
放在NSArray、NSDictionary等容器内的对象Item,Item中的property在程序运行过程中被无故释放

可能是被释放的property本身是OC对象而它的属性被误写成assign,例如:

@interface MyItem : Object
@property (nonatomic, assign) NSString *string;
@end
MyItem *item = [[MyItem alloc] init];
NSArray *array = @[item];

那么,在程序运行期间,一直在使用的array中的item对象,其string有可能会变成悬浮指针,导致读取时崩溃。