2009-06-29 10 views
3

私はiPhoneプラットフォームで非常に短期間で開発していますが、すでに私は文法上の誤りやメモリに関する問題を抱えています。iPhone SDK:私は記憶上の問題を抱えています。

私のiPhoneアプリでは、画像ビューが異なるボタン(6)で複数回アニメーション表示されていますが、問題なくiPhoneでうまく動作しますが、初めて計測器でアプリをテストしたときに、メモリリークが発生すると、アニメーションを実行するIBActionが呼び出され、サウンドエフェクトが発生するとメモリリークが発生します。今私はメモリリークが何であるかを理解していますが、それを防ぐことはほとんど分かりません。

後でアニメーションを追加する予定があることを心に留めて、 ヘルプは非常に高く評価されます。ここで が私のコードです:

#import "00001111ViewController.h" 
#import <AVFoundation/AVFoundation.h> 
#import <AudioToolbox/AudioToolbox.h> 
@implementation 00001111ViewController 


@synthesize leftSwitch; 
@synthesize rightSwitch; 
@synthesize switchView; 
@synthesize myScrollView1; 
@synthesize img; 
- (void)viewDidLoad { 

    blinkTimer = [NSTimer scheduledTimerWithTimeInterval:(1.00/1.00) target:self selector:@selector(blink) userInfo:nil repeats:NO]; 
    [blinkTimer setFireDate:[NSDate dateWithTimeIntervalSinceNow:rand()%10]]; 
} 

- (void)blink{ 
    [self animateBlink]; 
} 

- (void)animateBlink{ 

    UIImage *openeye = [UIImage imageNamed:@"img.png"]; 
    UIImage *closedeye = [UIImage imageNamed:@"cloudnewimprovedblinked.png"]; 

    if(img.image == openeye)  
     img.image = closedeye; 
else if(img.image == closedeye) 
     img.image = openeye; 

else 
    img.image == closedeye; 
    blinkTimer = [NSTimer scheduledTimerWithTimeInterval:0.2 target:self selector:@selector(blink) userInfo:nil repeats:NO]; 
if (img.image == openeye) 
    [blinkTimer setFireDate:[NSDate dateWithTimeIntervalSinceNow:rand()%10]]; 
} 
-(IBAction)toggleShowHide2:(id)sender 
{ 

    [UIView beginAnimations:nil context:NULL]; 
    [UIView setAnimationDuration:0.5]; 
    [switchView setAlpha:0]; 
    [UIView commitAnimations]; 

    [UIView beginAnimations:nil context:NULL]; 
    [UIView setAnimationDuration:0.5]; 
    [myScrollView1 setAlpha: 0]; 
    [UIView commitAnimations]; 
} 
-(IBAction)toggleShowHide1:(id)sender 
{ 
    [UIView beginAnimations:nil context:NULL]; 
    [UIView setAnimationDuration:0.5]; 
    [myScrollView1 setAlpha: 1]; 
    [UIView commitAnimations]; 

    [UIView beginAnimations:nil context:NULL]; 
    [UIView setAnimationDuration:0.5]; 
    [switchView setAlpha:.88]; 
    [UIView commitAnimations]; 
} 
- (IBAction)startClick:(id)sender{ 
    [UIView beginAnimations:nil context:NULL]; 
    [UIView setAnimationDuration:0.5]; 
    [switchView setAlpha:0]; 
    [UIView commitAnimations]; 
    [UIView beginAnimations:nil context:NULL]; 
    [UIView setAnimationDuration:0.5]; 
    [myScrollView1 setAlpha: 0]; 
    [UIView commitAnimations]; 
    sound1=[[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"clickwithsilence" ofType:@"wav"]] error:NULL]; 
    animationTimer = [NSTimer scheduledTimerWithTimeInterval:(1.00/30.00) target:self selector:@selector(tick) userInfo:nil repeats:NO]; 

    img.animationImages = [NSArray arrayWithObjects: 
           [UIImage imageNamed: @"imgapple0001.png"], 
           [UIImage imageNamed: @"imgapple0002.png"], 
           [UIImage imageNamed: @"imgapple0003.png"], 
           [UIImage imageNamed: @"imgapple0004.png"], 
           [UIImage imageNamed: @"imgapple0005.png"], 
           [UIImage imageNamed: @"imgapple0006.png"], 
           [UIImage imageNamed: @"imgapple0007.png"], 
           [UIImage imageNamed: @"imgapple0008.png"], 
           [UIImage imageNamed: @"imgapple0009.png"], 
           [UIImage imageNamed: @"imgapple0010.png"], 
           [UIImage imageNamed: @"imgapple0011.png"], 
           [UIImage imageNamed: @"imgapple0013.png"], 
           [UIImage imageNamed: @"imgapple0014.png"], 
           [UIImage imageNamed: @"imgapple0015.png"], 
           [UIImage imageNamed: @"imgapple0016.png"], 
           [UIImage imageNamed: @"imgapple0017.png"], 
           [UIImage imageNamed: @"imgapple0018.png"], 
           [UIImage imageNamed: @"imgapple0019.png"], 
           [UIImage imageNamed: @"imgapple0020.png"],nil]; 

    [img setAnimationRepeatCount:1]; 
    img.animationDuration =.7; 
    [img startAnimating]; 
    [sound1 play]; 
} 
- (void)tick{ 
    [self animateYes]; 
} 
- (void)animateYes{ 

    UIImage *YesImage13=[UIImage imageNamed:@"imgapple0020.png"]; 


    if(img.image == YesImage13) 
     img.image = YesImage13; 
    else 
     img.image = YesImage13; 
    if(img.image == YesImage13) 

     blinkTimer2 = [NSTimer scheduledTimerWithTimeInterval:(1.00/1.00) target:self selector:@selector(blink2) userInfo:nil repeats:NO]; 
    [blinkTimer2 setFireDate:[NSDate dateWithTimeIntervalSinceNow:rand()%7]]; 
} 

- (void)blink2{ 
    [self animateBlink2]; 
} 

- (void)animateBlink2{ 

    UIImage *openeye2 = [UIImage imageNamed:@"imgapple0020.png"]; 
    UIImage *closedeye2 = [UIImage imageNamed:@"appleblinked.png"]; 

    if(img.image == openeye2) 
     img.image = closedeye2; 
    else if(img.image == closedeye2) 
     img.image = openeye2; 

    else 
     img.image == closedeye2; 
    blinkTimer2 = [NSTimer scheduledTimerWithTimeInterval:0.2 target:self selector:@selector(blink2) userInfo:nil repeats:NO]; 
    if (img.image == openeye2) 
     [blinkTimer2 setFireDate:[NSDate dateWithTimeIntervalSinceNow:rand()%10]]; 







} 
- (IBAction)startClick1:(id)sender{ 
    [UIView beginAnimations:nil context:NULL]; 
    [UIView setAnimationDuration:0.2]; 
    [switchView setAlpha:0]; 
    [UIView commitAnimations]; 
    [UIView beginAnimations:nil context:NULL]; 
    [UIView setAnimationDuration:0.5]; 
    [myScrollView1 setAlpha: 0]; 
    [UIView commitAnimations]; 
    sound2=[[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"explosiontrimmed" ofType:@"wav"]] error:NULL]; 
    animationTimer1 = [NSTimer scheduledTimerWithTimeInterval:(1.00/30.00) target:self selector:@selector(tick1) userInfo:nil repeats:NO]; 
    img.animationImages = [NSArray arrayWithObjects: 
           [UIImage imageNamed: @"img0015.png"], 
           [UIImage imageNamed: @"img0016.png"], 
           [UIImage imageNamed: @"img0017.png"], 
           [UIImage imageNamed: @"img0018.png"], 
           [UIImage imageNamed: @"img0019.png"], 
           [UIImage imageNamed: @"img0020.png"], 
           [UIImage imageNamed: @"img0021.png"], 
           [UIImage imageNamed: @"img0022.png"], 
           [UIImage imageNamed: @"img0023.png"], 
           [UIImage imageNamed: @"img0024.png"], 
           [UIImage imageNamed: @"img0025.png"], 
           [UIImage imageNamed: @"img0026.png"], 
           [UIImage imageNamed: @"img0027.png"], 
           [UIImage imageNamed: @"img0028.png"], 
           [UIImage imageNamed: @"img0029.png"], 
           [UIImage imageNamed: @"img0030.png"], 
           [UIImage imageNamed: @"img0031.png"], 
           [UIImage imageNamed: @"img0032.png"], 
           [UIImage imageNamed: @"img0033.png"], 
           [UIImage imageNamed: @"img0034.png"], 
           [UIImage imageNamed: @"img0035.png"], 
           [UIImage imageNamed: @"img0036.png"], 
           [UIImage imageNamed: @"img0037.png"], 
           [UIImage imageNamed: @"img0038.png"], 
           [UIImage imageNamed: @"img0039.png"], 
           [UIImage imageNamed: @"img0040.png"], 
           [UIImage imageNamed: @"img0041.png"], 
           [UIImage imageNamed: @"img0042.png"], 
           [UIImage imageNamed: @"img0043.png"], 
           [UIImage imageNamed: @"img0044.png"], 
           [UIImage imageNamed: @"img0045.png"], 
           [UIImage imageNamed: @"img0046.png"], 
           [UIImage imageNamed: @"img0047.png"], 
           [UIImage imageNamed: @"img0048.png"], 
           //and so on to 100 
           nil]; 

    [img setAnimationRepeatCount:1]; 
    img.animationDuration =2.7; 
    [img startAnimating]; 
    [sound2 play]; 
} 
- (void)tick1{ 
    [self animateYes1]; 
} 
- (void) animateYes1{ 

    UIImage *YesImage11=[UIImage imageNamed:@"img0048.png"]; 


    if(img.image == YesImage11) 
     img.image = YesImage11; 
    else 
     img.image = YesImage11; 
    if(img.image == YesImage11) 

    blinkTimer1 = [NSTimer scheduledTimerWithTimeInterval:(1.00/1.00) target:self selector:@selector(blink1) userInfo:nil repeats:NO]; 
    [blinkTimer1 setFireDate:[NSDate dateWithTimeIntervalSinceNow:rand()%7]]; 
} 

- (void)blink1{ 
    [self animateBlink1]; 
} 

- (void)animateBlink1{ 

    UIImage *openeye1 = [UIImage imageNamed:@"img0048.png"]; 
    UIImage *closedeye1 = [UIImage imageNamed:@"explosionblinked.png"]; 

    if(img.image == openeye1) 
     img.image = closedeye1; 
    else if(img.image == closedeye1) 
     img.image = openeye1; 

    else 
     img.image == closedeye1; 
    blinkTimer1 = [NSTimer scheduledTimerWithTimeInterval:0.2 target:self selector:@selector(blink1) userInfo:nil repeats:NO]; 
    if (img.image == openeye1) 
     [blinkTimer1 setFireDate:[NSDate dateWithTimeIntervalSinceNow:rand()%7]]; 
} 








- (IBAction)startClick2:(id)sender{ 
    [UIView beginAnimations:nil context:NULL]; 
    [UIView setAnimationDuration:0.2]; 
    [switchView setAlpha:0]; 
    [UIView commitAnimations]; 
    [UIView beginAnimations:nil context:NULL]; 
    [UIView setAnimationDuration:0.5]; 
    [myScrollView1 setAlpha: 0]; 
    [UIView commitAnimations]; 
    sound3=[[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"watersplashsilence" ofType:@"wav"]] error:NULL]; 
    animationTimer2 = [NSTimer scheduledTimerWithTimeInterval:(1.00/30.00) target:self selector:@selector(tick2) userInfo:nil repeats:NO]; 

    img.animationImages = [NSArray arrayWithObjects: 

           [UIImage imageNamed: @"imgshark0001.png"], 
           [UIImage imageNamed: @"imgshark0002.png"], 
           [UIImage imageNamed: @"imgshark0003.png"], 
           [UIImage imageNamed: @"imgshark0004.png"], 
           [UIImage imageNamed: @"imgshark0005.png"], 
           [UIImage imageNamed: @"imgshark0006.png"], 
           [UIImage imageNamed: @"imgshark0007.png"], 
           [UIImage imageNamed: @"imgshark0008.png"], 
           [UIImage imageNamed: @"imgshark0009.png"], 
           [UIImage imageNamed: @"imgshark0010.png"], 
           [UIImage imageNamed: @"imgshark0011.png"], 
           [UIImage imageNamed: @"imgshark0012.png"], 
           [UIImage imageNamed: @"imgshark0013.png"], 
           [UIImage imageNamed: @"imgshark0014.png"], 
           [UIImage imageNamed: @"imgshark0015.png"], 
           [UIImage imageNamed: @"imgshark0016.png"], 
           [UIImage imageNamed: @"imgshark0017.png"], 
           [UIImage imageNamed: @"imgshark0018.png"], 
           [UIImage imageNamed: @"imgshark0019.png"], 
           [UIImage imageNamed: @"imgshark0020.png"], 
           [UIImage imageNamed: @"imgshark0021.png"], 
           [UIImage imageNamed: @"imgshark0022.png"], 
           [UIImage imageNamed: @"imgshark0023.png"], 
           [UIImage imageNamed: @"imgshark0024.png"], 
           [UIImage imageNamed: @"imgshark0025.png"], 
           [UIImage imageNamed: @"imgshark0026.png"], 
           [UIImage imageNamed: @"imgshark0027.png"], 
           [UIImage imageNamed: @"imgshark0028.png"], 
           [UIImage imageNamed: @"imgshark0029.png"], 
           [UIImage imageNamed: @"imgshark0030.png"], 
           [UIImage imageNamed: @"imgshark0031.png"], 
           [UIImage imageNamed: @"imgshark0032.png"], 
           [UIImage imageNamed: @"imgshark0033.png"], 
           [UIImage imageNamed: @"imgshark0034.png"],nil]; 

    [img setAnimationRepeatCount:1]; 
    img.animationDuration =2.8; 
    [img startAnimating]; 
    [sound3 play]; 
} 
- (void)tick2{ 
    [self animateYes2]; 
} 
- (void)animateYes2{ 

    UIImage *YesImage14=[UIImage imageNamed:@"imgshark0034.png"]; 


    if(img.image == YesImage14) 
     img.image = YesImage14; 
    else 
     img.image = YesImage14; 






} 
- (IBAction)startClick3:(id)sender{ 
    [UIView beginAnimations:nil context:NULL]; 
    [UIView setAnimationDuration:0.2]; 
    [switchView setAlpha:0]; 
    [UIView commitAnimations]; 
    [UIView beginAnimations:nil context:NULL]; 
    [UIView setAnimationDuration:0.5]; 
    [myScrollView1 setAlpha: 0]; 
    [UIView commitAnimations]; 
    sound4=[[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"dogsilence" ofType:@"wav"]] error:NULL]; 

    animationTimer3 = [NSTimer scheduledTimerWithTimeInterval:(1.00/30.00) target:self selector:@selector(tick3) userInfo:nil repeats:NO]; 

    img.animationImages = [NSArray arrayWithObjects: 
           [UIImage imageNamed: @"imgdog0001.png"], 
           [UIImage imageNamed: @"imgdog0002.png"], 
           [UIImage imageNamed: @"imgdog0003.png"], 
           [UIImage imageNamed: @"imgdog0004.png"], 
           [UIImage imageNamed: @"imgdog0005.png"], 
           [UIImage imageNamed: @"imgdog0006.png"], 
           [UIImage imageNamed: @"imgdog0007.png"], 
           [UIImage imageNamed: @"imgdog0008.png"], 
           [UIImage imageNamed: @"imgdog0009.png"], 
           [UIImage imageNamed: @"imgdog0010.png"], 
           [UIImage imageNamed: @"imgdog0011.png"], 
           [UIImage imageNamed: @"imgdog0012.png"], 
           [UIImage imageNamed: @"imgdog0013.png"], 
           [UIImage imageNamed: @"imgdog0014.png"], 
           [UIImage imageNamed: @"imgdog0015.png"], 
           [UIImage imageNamed: @"imgdog0016.png"], 
           [UIImage imageNamed: @"imgdog0017.png"], 
           [UIImage imageNamed: @"imgdog0018.png"], 
           [UIImage imageNamed: @"imgdog0019.png"], 
           [UIImage imageNamed: @"imgdog0020.png"], 
           [UIImage imageNamed: @"imgdog0021.png"], 
           [UIImage imageNamed: @"imgdog0022.png"], 
           [UIImage imageNamed: @"imgdog0023.png"], 
           [UIImage imageNamed: @"imgdog0024.png"], 
           [UIImage imageNamed: @"imgdog0025.png"], 
           [UIImage imageNamed: @"imgdog0026.png"], 
           [UIImage imageNamed: @"imgdog0026.png"], 
           [UIImage imageNamed: @"imgdog0028.png"], 
           [UIImage imageNamed: @"imgdog0029.png"], 
           [UIImage imageNamed: @"imgdog0030.png"], 
           [UIImage imageNamed: @"imgdog0031.png"], 
           [UIImage imageNamed: @"imgdog0032.png"], 
           [UIImage imageNamed: @"imgdog0033.png"], 
           [UIImage imageNamed: @"imgdog0034.png"],nil]; 

    [img setAnimationRepeatCount:1]; 
    img.animationDuration =2.7; 
    [img startAnimating]; 
    [sound4 play]; 
} 
- (void)tick3{ 
    [self animateYes3]; 

} 
- (void)animateYes3{ 

    UIImage *YesImage14=[UIImage imageNamed:@"imgdog0034.png"]; 


    if(img.image == YesImage14) 
     img.image = YesImage14; 
    else 
     img.image = YesImage14; 






} 
- (IBAction)startClick4:(id)sender{ 
    [UIView beginAnimations:nil context:NULL]; 
    [UIView setAnimationDuration:0.2]; 
    [switchView setAlpha:0]; 
    [UIView commitAnimations]; 
    [UIView beginAnimations:nil context:NULL]; 
    [UIView setAnimationDuration:0.5]; 
    [myScrollView1 setAlpha: 0]; 
    [UIView commitAnimations]; 
    sound5=[[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"arrowhitting" ofType:@"wav"]] error:NULL]; 
    animationTimer4 = [NSTimer scheduledTimerWithTimeInterval:(1.00/30.00) target:self selector:@selector(tick4) userInfo:nil repeats:NO]; 

    img.animationImages = [NSArray arrayWithObjects: 

           [UIImage imageNamed: @"imgarrow0001.png"], 
           [UIImage imageNamed: @"imgarrow0002.png"], 
           [UIImage imageNamed: @"imgarrow0003.png"], 
           [UIImage imageNamed: @"imgarrow0004.png"], 
           [UIImage imageNamed: @"imgarrow0005.png"], 
           [UIImage imageNamed: @"imgarrow0006.png"], 
           [UIImage imageNamed: @"imgarrow0007.png"], 
           [UIImage imageNamed: @"imgarrow0008.png"], 
           [UIImage imageNamed: @"imgarrow0009.png"], 
           [UIImage imageNamed: @"imgarrow0010.png"], 
           [UIImage imageNamed: @"imgarrow0011.png"], 
           [UIImage imageNamed: @"imgarrow0012.png"], 
           [UIImage imageNamed: @"imgarrow0013.png"], 
           [UIImage imageNamed: @"imgarrow0014.png"], 
           [UIImage imageNamed: @"imgarrow0015.png"], 
           [UIImage imageNamed: @"imgarrow0016.png"], 
           [UIImage imageNamed: @"imgarrow0017.png"], 
           [UIImage imageNamed: @"imgarrow0018.png"], 
           [UIImage imageNamed: @"imgarrow0019.png"], 
           [UIImage imageNamed: @"imgarrow0020.png"], 
           [UIImage imageNamed: @"imgarrow0021.png"], 
           [UIImage imageNamed: @"imgarrow0022.png"], 
           [UIImage imageNamed: @"imgarrow0023.png"], 
           [UIImage imageNamed: @"imgarrow0024.png"],nil]; 

    [img setAnimationRepeatCount:1]; 
    img.animationDuration =.7; 
    [img startAnimating]; 
    [sound5 play]; 
} 
- (void)tick4{ 
    [self animateYes4]; 
} 
- (void)animateYes4{ 

    UIImage *YesImage15=[UIImage imageNamed:@"imgarrow0024.png"]; 


    if(img.image == YesImage15) 
     img.image = YesImage15; 
    else 
     img.image = YesImage15; 






} 
- (IBAction)startClick5:(id)sender{ 
    [UIView beginAnimations:nil context:NULL]; 
    [UIView setAnimationDuration:0.5]; 
    [switchView setAlpha:0]; 
    [UIView commitAnimations]; 
    [UIView beginAnimations:nil context:NULL]; 
    [UIView setAnimationDuration:0.5]; 
    [myScrollView1 setAlpha: 0]; 
    [UIView commitAnimations]; 
    sound6=[[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"imgquote1" ofType:@"wav"]] error:NULL]; 
    animationTimer5 = [NSTimer scheduledTimerWithTimeInterval:(1.00/30.00) target:self selector:@selector(tick5) userInfo:nil repeats:NO]; 

    img.animationImages = [NSArray arrayWithObjects: 
           [UIImage imageNamed: @"qotebandb0000.png"], 
           [UIImage imageNamed: @"qotebandb0001.png"], 
           [UIImage imageNamed: @"qotebandb0002.png"], 
           [UIImage imageNamed: @"qotebandb0003.png"], 
           [UIImage imageNamed: @"qotebandb0004.png"], 
           [UIImage imageNamed: @"qotebandb0005.png"], 
           [UIImage imageNamed: @"qotebandb0006.png"], 
           [UIImage imageNamed: @"qotebandb0007.png"], 
           [UIImage imageNamed: @"qotebandb0008.png"], 
           [UIImage imageNamed: @"qotebandb0009.png"], 
           [UIImage imageNamed: @"qotebandb0010.png"], 
           [UIImage imageNamed: @"qotebandb0011.png"], 
           [UIImage imageNamed: @"qotebandb0012.png"], 
           [UIImage imageNamed: @"qotebandb0013.png"], 
           [UIImage imageNamed: @"qotebandb0014.png"], 
           [UIImage imageNamed: @"qotebandb0015.png"], 
           [UIImage imageNamed: @"qotebandb0016.png"], 
           [UIImage imageNamed: @"qotebandb0017.png"], 
           [UIImage imageNamed: @"qotebandb0018.png"], 
           [UIImage imageNamed: @"qotebandb0019.png"], 
           [UIImage imageNamed: @"qotebandb0020.png"], 
           [UIImage imageNamed: @"qotebandb0021.png"], 
           [UIImage imageNamed: @"qotebandb0022.png"], 
           [UIImage imageNamed: @"qotebandb0023.png"], 
           [UIImage imageNamed: @"qotebandb0024.png"], 
           [UIImage imageNamed: @"qotebandb0025.png"], 
           [UIImage imageNamed: @"qotebandb0026.png"], 
           [UIImage imageNamed: @"qotebandb0027.png"], 
           [UIImage imageNamed: @"qotebandb0028.png"], 
           [UIImage imageNamed: @"qotebandb0029.png"], 
           [UIImage imageNamed: @"qotebandb0030.png"], 
           [UIImage imageNamed: @"qotebandb0031.png"], 
           [UIImage imageNamed: @"qotebandb0032.png"], 
           [UIImage imageNamed: @"qotebandb0033.png"], 
           [UIImage imageNamed: @"qotebandb0034.png"], 
           [UIImage imageNamed: @"qotebandb0035.png"], 
           [UIImage imageNamed: @"qotebandb0036.png"], 
           [UIImage imageNamed: @"qotebandb0037.png"], 
           [UIImage imageNamed: @"qotebandb0038.png"],nil]; 

    [img setAnimationRepeatCount:1]; 
    img.animationDuration =3.1; 
    [img startAnimating]; 
    [sound6 play]; 
} 
- (void)tick5{ 
    [self animateYes5]; 
} 
- (void)animateYes5{ 

    UIImage *YesImage17=[UIImage imageNamed:@"qotebandb0038.png"]; 


    if(img.image == YesImage17) 
     img.image = YesImage17; 
    else 
     img.image = YesImage17; 

} 
- (IBAction)startClick6:(id)sender{ 
    [UIView beginAnimations:nil context:NULL]; 
    [UIView setAnimationDuration:0.5]; 
    [switchView setAlpha:0]; 
    [UIView commitAnimations]; 
    [UIView beginAnimations:nil context:NULL]; 
    [UIView setAnimationDuration:0.5]; 
    [myScrollView1 setAlpha: 0]; 
    [UIView commitAnimations]; 
    sound7=[[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"audiop" ofType:@"wav"]] error:NULL]; 
    animationTimer6 = [NSTimer scheduledTimerWithTimeInterval:(1.00/30.00) target:self selector:@selector(tick6) userInfo:nil repeats:NO]; 

    img.animationImages = [NSArray arrayWithObjects: 
           [UIImage imageNamed: @"hammer0001.png"], 
           [UIImage imageNamed: @"hammer0002.png"], 
           [UIImage imageNamed: @"hammer0003.png"], 
           [UIImage imageNamed: @"hammer0004.png"], 
           [UIImage imageNamed: @"hammer0005.png"], 
           [UIImage imageNamed: @"hammer0006.png"], 
           [UIImage imageNamed: @"hammer0007.png"], 
           [UIImage imageNamed: @"hammer0008.png"], 
           [UIImage imageNamed: @"hammer0009.png"], 
           [UIImage imageNamed: @"hammer0010.png"], 
           [UIImage imageNamed: @"hammer0011.png"], 
           [UIImage imageNamed: @"hammer0012.png"], 
           [UIImage imageNamed: @"hammer0013.png"], 
           [UIImage imageNamed: @"hammer0014.png"], 
           [UIImage imageNamed: @"hammer0015.png"], 
           [UIImage imageNamed: @"hammer0016.png"], 
           [UIImage imageNamed: @"hammer0017.png"], 
           [UIImage imageNamed: @"hammer0018.png"], 
           [UIImage imageNamed: @"hammer0019.png"], 
           [UIImage imageNamed: @"hammer0020.png"], 
           [UIImage imageNamed: @"hammer0021.png"], 
           [UIImage imageNamed: @"hammer0022.png"], 
           [UIImage imageNamed: @"hammer0023.png"], 
           [UIImage imageNamed: @"hammer0024.png"], 
           [UIImage imageNamed: @"hammer0025.png"], 
           [UIImage imageNamed: @"hammer0026.png"], 
           [UIImage imageNamed: @"hammer0027.png"], 
           [UIImage imageNamed: @"hammer0028.png"], 
           [UIImage imageNamed: @"hammer0029.png"], 
           [UIImage imageNamed: @"hammer0030.png"], 
           [UIImage imageNamed: @"hammer0031.png"], 
           [UIImage imageNamed: @"hammer0032.png"], 
           [UIImage imageNamed: @"hammer0033.png"], 
           [UIImage imageNamed: @"hammer0034.png"],nil]; 

    [img setAnimationRepeatCount:1]; 
    img.animationDuration =2.25; 
    [img startAnimating]; 
    [sound7 play]; 
} 
- (void)tick6{ 
    [self animateYes6]; 
} 
- (void)animateYes6{ 

    UIImage *YesImage18=[UIImage imageNamed:@"img.png"]; 


    if(img.image == YesImage18) 
     img.image = YesImage18; 
    else 
     img.image = YesImage18; 






} 




- (void)stopTimer 
{ 
    [animationTimer invalidate]; 
    [animationTimer release]; 
    [animationTimer1 invalidate]; 
    [animationTimer1 release]; 
    [animationTimer2 invalidate]; 
    [animationTimer2 release]; 
    [animationTimer3 invalidate]; 
    [animationTimer3 release]; 
    [blinkTimer invalidate]; 
    [blinkTimer release]; 
} 







-(void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { 
    UITouch *touch = [[event allTouches] anyObject]; 
    CGPoint location = [touch locationInView:touch.view]; 
    img.center = location; 
} 

- (void)didReceiveMemoryWarning { 
    [super didReceiveMemoryWarning]; 
} 

// Releases the view if it doesn't have a superview 
// Release anything that's not essential, such as cached data 



- (void)dealloc { 
    [super dealloc]; 
    [img release]; 
    [sound1 release]; 
    [sound2 release]; 
    [sound3 release]; 
    [sound4 release]; 
    [sound5 release]; 
    [sound6 release]; 
    [sound7 release]; 
} 
@end 

だけ明確にするために、タイマーはImageViewの画像のように、個々のアニメーションに最後のフレームを設定するために使用されています。

答えて

1

理想的にはメモリリークはありません。しかし、あなたはそれをこのように見ることを選択することができます:1クリックにつき数キロバイトしか失われておらず、クリック数が増えない場合、ほとんど問題になりません。インストゥルメントが私のコードではないコードでメモリリークを報告しているのを見ましたが(フレームワークコード、それはほんの数KBであり、非常に散発的にしか起こらなかったので、問題ありません)。それは良い習慣ではありませんが、とにかく修正できないリークを追跡する時間を無駄にすることは、あなたの時間を有効に活用することではありません。

もし漏れが制御不能にならないことが確かであれば、それをそのまま残すこともできます。しかし、このリークが数十回または数百回起こり、KBsが漏洩して100秒に達すると、すばやく自分が困ったことに気付くことがあります。あなたのリソースはiPhone上で制限されており、リークはiPhoneアプリケーションのクラッシュの第1の理由です。

コードを手助けするために、私はClang Static Analyzerツールが非常に便利であることを発見しました。ツールhereのGUIがあります。あなたのコードでリークやその他のレビューが必要な領域のレポートを生成します。

1つ以上:Objective-Cのメモリ管理の一般的なルールは、オブジェクトを割り当て、コピー、または保持する場合に解放する必要があることです。それ以外の場合は、そのままにします。ほとんどのリークは、[[MyObject alloc] init]のようなコードがある場所を見つけて、そのあとで[MyObject release]を必ず呼び出すことで解決できます。

あなたが init方法

でイメージを保持NSArraysを作成することができます。そして、あなたがで画像を置くことで、パターンを見つけることについて考えるかもしれない。これは、引数としてパスをループしとる関数を作る手始めに

+0

+1(その他の回答も)。 –

0

イメージを配列に格納します。

3

私は潜在的なメモリは、あなたがAVAudioPlayerオブジェクトを割り当てるあなたのコードを漏らす見ることができます:

sound1=[[AVAudioPlayer alloc] initWithContentsOfURL:... 

私はsound#変数はあなたが忠実に自分の-(void)dealloc方法で解放するインスタンス変数であることを、あなたのコードから見ることができます。ただし、クラスの存続期間中にその特定のアクションを2回以上開始すると、リークが発生します。アクションが発生するたびに、sound1は新しいAVAudioPlayerオブジェクトを取得し、直ちに古いものへの参照を失います。

[sound1 release]; 
sound1 = [[AVAudioPlayer alloc] initWithContentsOfUrl: ... 

をそして必ず設定してください:

私は、次の追加を示唆している

sound1 = nil; 

をご-(id)init方法で[sound1 release]への最初の呼び出しがトラブルを起こさないように。

更新:メモリリークを防ぐために、親指の

ルールがある:たびあなたalloccopy、またはretainオブジェクト、あなたがそれもrelease必要があります。

ここで数KBが漏れてしまうのではないでしょうか?私ははいと言うだろう。あなたが自分の仕事を気にしているなら、それをできるだけベストにしようと努力すべきです。私はあなたがをしないと言っているわけではないよ小さなメモリリークを持つリリースコード。私は小さなメモリリークはバグとみなされるべきだと言っています。彼らはあなたの "解決すべき問題"リストに表示されるべきであり、できるだけ早くそれらを削除するように努めるべきです。コメントする

応答:

あなた00001111ViewControllerクラスはメソッドが-(id)initと呼ばれている必要があります。

- (id)init 
{ 
    if ((self = [super init]) == nil) { return nil; } 

    sound1 = nil; 
    sound2 = nil; 
    //... 

    return self; 
} 

あなたのクラスのインスタンスが作成されたときinitメソッド内のコードは多くのように、実行されますdeallocメソッドのコードは、クラスのインスタンスが破棄されたときに呼び出されます。スーパークラス(00001111ViewControllerから継承するクラス)が別の指定された初期化子を使用する場合は、代わりにそのメソッド名を使用する必要があることに注意してください。ココアの世界では、イニシャライザは常にinitで始まりますが、さらなる引数(initWithNibName:bundle:initWithContentsOfFile:など)が必要な場合があります。

別の更新:いくつかのより多くの思考の後

、おそらくあなたのviewDidLoad方法では、一度だけAVAudioPlayerオブジェクトを割り当てる方が良いでしょう。それが行わ付き

- (void)viewDidLoad 
{ 
    blinkTimer = [NSTimer ... 
    [blinkTimer setFireDate: ... 

    sound1 = [[AVAudioPlayer alloc] initWithContentsOfUrl: ... 
    sound2 = [[AVAudioPlayer alloc] initWithContentsOfUrl: ... 
    sound3 = [[AVAudioPlayer alloc] initWithContentsOfUrl: ... 
} 

、あなたはもはやあなたのstartClick方法でそれらを毎回再作成する必要はないだろう。これらのメソッドの最後に[sound1 play]と呼ぶだけで十分です。

+0

親切なアドバイスをいただきありがとうございます。私はあなたの提案を試し、彼らがメモリリークを助けたかどうかを教えてくれるでしょう。ちなみに、Apple Storeに提出する際のメモリリークに関するAppleの見解は何ですか?ここに2,3キロも漏れた場合、アプリを拒否しますか? –

+0

私の喜び!残念ながら、App Storeのポリシーがメモリリークに関するものであるかどうかはわかりません。良い質問。 –

+0

私はAVAudio割り当ての前にそれをリリースするというあなたの提案を試みましたが、残念ながら楽器はまだオーディオでメモリリークを検出しています。私はIBAcionが宣言された直後に言いました。そして、まだメモリリークが残っている、私はボタンを押して初めてメモリリークが表示されませんが、3番目。私が次に試してみたいことに関するアイデアは何ですか?前もって感謝します。 –

0

最初の答えは間違いなく使用することは良いことです静的アナライザを、指摘しています。使用するもう一つの良い点は、実行時に割り当て/割り当て解除とメモリアクセスを監視するダイナミックアナライザです。 Valgrindは、Linuxで一般的に使用されている一般的なオープンソースのダイナミックアナライザです。

Valgrind can work on OSX(「サポートされていない、不完全でバグがある」と言われていますが)、ちょっとハッキングすると誰かがiPhone SDK executablesで作業するようになりました。

さらに良いことに、XCodeの一部であるInstrumentsを試すことができます。それを実行するためのチュートリアルがhereです。

0

はい、まだメモリリークがあります。 3回目のプレスで

+0

答えに最新のアップデートを投稿したので、[AVAudioPlayer alloc]メソッドをviewDidLoadに配置しようとしましたか?長距離デバッグは難しいです:) –

+0

はい、3回目のプレス後に残念なことに、メモリリークが見つかりました。理論的には、あなたが言ったことはこのトリックを行うべきだったので、最近はメモリリークが発生しているというのは奇妙なことです。 – Amanda

関連する問題