objective c - week reference to autoreleased object not getting deallocated in case of NSString -
why temp object not released , set nil though declared __week. in case of person object working expected. nsstring objects memory life cycle handled differently? how?
@interface person : nsobject @property(nonatomic, strong) nsstring *name; - (instancetype)initwithname:(nsstring *)name; + (person *)personwithname:(nsstring *)name; @end @implementation person - (instancetype)initwithname:(nsstring *)name { if (self = [super init]) { self.name = name; } return self; } + (person *)personwithname:(nsstring *)name { return [[self alloc] initwithname: name]; } @end - (void)viewdidload { __weak nsstring *temp; @autoreleasepool { nsmutablearray *data = [[nsmutablearray alloc] initwithobjects:@"firststring", @"secondstring", nil]; temp = data[0]; [data removeobjectatindex:0]; } nslog(@"%@", temp);//prints firststring instead of null __weak person *person ; @autoreleasepool { nsmutablearray *persons = [[nsmutablearray alloc] initwithobjects:[person personwithname:@"steve"], [person personwithname:@"harry"], nil]; person = persons[0]; [persons removeobjectatindex:0]; } nslog(@"%@", person.name);//prints null expected because person object deallocated, }
constant strings never released. there other objects never released, nsnumber objects (on 64 bit versions, nsnumber objects).
it makes me wonder to. want if nsstring* becomes nil (which won't)?
Comments
Post a Comment