Here is some of the code from one of my classes, I was wondering am I handling the memory right or am I leaking anywhere?
@implementation CardViewController
@synthesize playerImage;
@synthesize cardLabel;
@synthesize card;
@synthesize frontView;
@synthesize backView;
@synthesize nameLabel;
@synthesize infoLabel;
@synthesize delegate;
-(void) initialiseButtons
{
NSLog(@"initialiseButtons %d",totalButtons);
int ypos = playerImage.frame.origin.y + playerImage.frame.size.height + 42;
for(int i=0; i<totalButtons; i++)
{
StatView *sv = [[StatView alloc] initWithYPos:ypos];
sv.tag = 100 + i;
[sv.overlayButton addTarget:self action:@selector(statTapped:)
forControlEvents:UIControlEventTouchUpInside];
sv.overlayButton.tag = 10 + i;
[self.frontView addSubview:sv];
ypos += 26;
}
}
-(IBAction) statTapped:(id) sender
{
UIButton *tappedButton = (UIButton *)sender;
int tag = tappedButton.tag;
if(delegate && [delegate respondsToSelector:@selector(cardTapped:)]) {
[delegate cardTapped:tag-10];
}
}
-(void) viewDidLoad
{
NSLog(@" viewDidLoad CVC");
[self initialiseButtons];
metaData = [[NSArray alloc]
initWithObjects:@"Height",@"Weight",@"Games",@"Attack",@"Defense", nil];
}
-(void) setCard:(Card *)newCard
{
NSLog(@"setCard");
[card release];
card = [newCard retain];
[self updateUI];
}
- (void)dealloc
{
[card autorelease];
[metaData autorelease];
[super dealloc];
}
@end
Where should I release StatView *sv = [[StatView alloc] initWithYPos:ypos]; If i released it every loop wouldnt that cause problems? Besides that do I handle the rest of the memory ok?
Thanks -Code