from researching memory management on objective C, I have a question about reference count:
I have an object name obj_number. I have alloc it
obj_number = [[NSNumber alloc] init];
and then in another method (named A)of this class, I set
obj_number = [dataset objectAtIndex:0];
go out this method A dataset will be autorelease. I checked this after go out this method obj_number also can’t be access, maybe it also be deallocate.
I see if an object just be under one ownership, so if parent deallocate it also be deallocate, but in my case I suppose that obj_number under 2 ownership (retain count may equals to 2), so why running out method A it be released?
You need to provide a setter method for
obj_number, which you can do by providing a@propertyin the.hfile and a@sythesizein the.mfile. The setter method will ensure that the old value is released and the new value is retained.MyClass.h:
MyClass.m:
And when assigning to
obj_number, you must relinquish ownership: