I have a method:
- (void)setName:(ModelClass *)model {
[model release];
ModelClass *tmp = [[[ModelClass alloc] initWithId:@"New"] autorelease];
model = [tmp retain];
NSLog([NSString stringWithFormat:@"Gia tri trong la %@",model.modelClassId]);
}
and
- (void)viewDidLoad {
[super viewDidLoad];
ModelClass *tmp3 = [[ModelClass alloc] initWithId:@"Old"];
[self setName:tmp3];
ModelClass *tmp4 = [[ModelClass alloc] initWithId:@"Old"];
ModelClass *tmp5 = [[ModelClass alloc] initWithId:@"Old"];
ModelClass *tmp6 = [[ModelClass alloc] initWithId:@"Old"];
ModelClass *tmp7 = [[ModelClass alloc] initWithId:@"Old"];
NSLog(tmp3.modelClassId);
}
It runs OK. But when i write:
- (void)setName:(ModelClass *)model {
ModelClass *tmp = [[[ModelClass alloc] initWithId:@"New"] autorelease];
[model release];
model = [tmp retain];
NSLog([NSString stringWithFormat:@"Gia tri trong la %@",model.modelClassId]);
}
it breaks my app. Anybody can explain to me what the difference is between the two cases?