I wish to create multiple instances of UIView so i figured instead of creating new variables i’d allocate one UIView and then reallocate it again to create another UIView. Is this ok? Plus am I releasing the view properly or is the retain count of tempview is 2 after 2 allocations and a release just brings the retain count to 1?
NSMutableArray *array = [[NSMutableArray alloc] init];
UIView *tempview = [[UIView alloc] initWithFrame:CGRectMake(15, 30, 320, 460)];
[array addObject:tempView];
tempview = [[UIView alloc] initWithFrame:CGRectMake(15, 30, 320, 460)];
[array addObject:tempView];
[tempview release];
[array release];
You need to release tempView before you re-assign it or else it will leak.
Alternately, you could autorelease tempView each time you alloc/init it, but it’s better to release when you can and only use autorelease when you have to.