Hi everyone, I'm developing an iPhone app and have a question about memory management.
Let's say I have a class called Company
with a NSNumber property(nonatomic,retain)
called Id
.
I do this:
Company *company = [[Company alloc] initWithId:[NSNumber numberWithInt:1]];
Id should now have a retain count of 1? Then I do:
NSMutableArray *array = [[NSMutableArray alloc] init];
[array addObject:company];
[company release];
What will the retain count on Id be now? Still 1?
I should add that in the dealloc
method in Company
I do [self.Id release]
.
The problem is that when i do this in my app and later try to access [[array objectAtIndex:0] Id]
it is out of scope. From my point of view the array retains company and therefore I should be able to access Id
"through" the array. Is this correct?
Edit: Forgot to say that when I remove [self.Id release]
from Company
the app works, if it's there it crashes...
Thanks!