【发布时间】:2010-09-15 04:33:43
【问题描述】:
这是我的一个课程中的一些代码,我想知道我是在正确处理内存还是在任何地方泄漏?
@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
我应该在哪里释放 StatView *sv = [[StatView alloc] initWithYPos:ypos]; 如果我在每个循环中释放它不会导致问题吗? 除此之外,我还能处理剩下的内存吗?
谢谢 -代码
【问题讨论】:
-
是否有可以在帖子中使用的标签,以便我发布的代码的 sn-ps 显示得很好?
-
是的 - 指示在您输入问题的位置。使用四个空格或 101010 按钮。
标签: iphone objective-c