I have an NSMutableArray property defined in my Brain model.
@property (retain, nonatomic) NSMutableArray *stockColors;
The mutable array gets filled with objects during the Brain init.
In my view controller viewDidLoad function I do
*Brain brain = [[Brain alloc]init];
NSLog(@"Brain stockColors is %@", brain.stockColors);
This works well, and it logs a memory address as expected.
Then in the same view controller I have an “addButtonPressed” action declared linked to a UIButton in the .xib.
In my addbuttonPressed action if I try and do the exact same log
NSLog(@"Brain stockColors is %@", brain.stockColors);
The program crashes!
If I do
NSLog(@"Brain stockColors is %@", brain);
I get an address for the brain… so the brain exists.. but for some reason it seems that brain.stockColors is getting released or something by the time I get to the addButtonPressed action.
Can anyone explain what would cause it to get autoreleased?
Thanks
Considering you left out the important code… the actual
Braininit call I am going to say that when you create your mutable array you are assigning to the instance variable and not the property.