views:

1362

answers:

6

Hello, I have been developing on the iPhone platform for a very short time, and already I've had my fare share of syntax errors, and now memory issues.

In my iPhone app an image view is animated multiple times by different buttons(6), and this works well on the iPhone without problems, but when I tested my app with instruments for the first time, it found 1 or 2 memory leaks, the memory leaks occur when an IBAction is called that executes an animation and It's sound effect. Now I understand what a memory leak is, but know little on preventing them,

Should I even be worried about a few kb memory leak, bearing in mind that I plan to add more animations later? Help will be appreciated greatly. Here is my code:

#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

Just to clarify, the timers are used to set each individual animations last frame to be the image of the imageView.

+1  A: 

Ideally you'd have no memory leaks. But you can choose to look at it this way: If it's only a few KBs lost with each click, and there aren't going to be many clicks, then it's hardly an issue. I've seen Instruments report memory leaks on code that isn't mine (framework code, that is) and it was only a few KBs and it only happened very sporadically, so I decided it's OK. It's not a good practice, but wasting hours tracking down a leak that you can't fix anyway isn't a good use of your time either.

So if you can be sure that the leak won't get out of control, you might be ok to leave it there. But if this leak is going to happen many dozens or hundreds of times, adding up to 100s of KBs leaked, then you could quickly find yourself in trouble. Your resources are limited on the iPhone and leaks are the number one reason for iPhone application crashes.

To help you with your code, I find that the Clang Static Analyzer tool is very useful. There's a GUI for the tool here. It will generate a report of leaks and other areas needing review in your code.

ONE MORE THING: The general rule of memory management in Objective-C is if you alloc, copy, or retain an object, you must release it. Otherwise leave it alone. Most leaks can be resolved by finding any place where you have code like [[MyObject alloc] init] and making sure you call [MyObject release] sometime after that.

Ken Pespisa
+1 for Clang (and the rest of your answer, too).
e.James
A: 

For starters you could create the NSArrays holding the images in the init method

And then you might think about finding a pattern in putting the images in. Make a function that loops and takes the path as an argument which puts the images into the array.

nasmorn
+3  A: 

I can see a potential memory leak your code where you allocate the AVAudioPlayer objects:

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

I can see from your code that the sound# variables are instance variables which you dutifully release in your -(void)dealloc method. However, the leak would occur when you initiate that particular action more than once during the lifetime of the class. Each time the action is fired, sound1 gets a brand new AVAudioPlayer object, and promptly loses the reference to the old one.

I would suggest adding the following:

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

And be sure to set:

sound1 = nil;

In your -(id)init method so that the first call to [sound1 release] doesn't cause trouble.

update:

The rule of thumb to prevent memory leaks is: Whenever you alloc, copy, or retain an object, you must also release it.

Should you worry about a few KB leaked here and there? I would say yes. If you care about your work, you should endeavour to make it the best it can be. I'm not saying you should never release code that has a small memory leak. I'm saying that small memory leaks should be considered bugs. They should show up in your list of "issues to be resolved", and you should work to remove them as soon as possible.

response to comment:

Your 00001111ViewController class should have a method called -(id)init:

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

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

    return self;
}

The code inside the init method is run when an instance of your class is created, much like the code in the dealloc method is called when an instance of your class is destroyed. Note that if your superclass (the class that 00001111ViewController inherits from) uses a different designated initializer, you should use that method name instead. In the Cocoa world, initializers always begin with init, but they may take further arguments, such as initWithNibName:bundle: or initWithContentsOfFile:.

another update:

After some more thought, perhaps it would be better to allocate the AVAudioPlayer objects only once, in your viewDidLoad method.

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

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

With that done, you would no longer need to re-create them every time in your startClick methods. All you would have to do is call [sound1 play] at the end of those methods, and all would be well.

e.James
Okay, thanks for the helpful advice. I'll try your suggestions and tell you if they've helped the memory leaks. By the way, what's apple's views on memory leaks when submitting to the app store, would they reject a app if it leaked a couple of kb here and there?
My pleasure! Unfortunately, I have no idea what the App Store policy is regarding memory leaks. Good question.
e.James
I've tried your suggestion of releasing it before the AVAudio allocation and unfortunately instruments is still finding a memory leak with the audio, I'm not sure where you meant for me to set sound1 = nil; so I put it right after my IBAcion was declared. And still the memory leak remains, the memory leak isn't seen the first time I press the button, but the third. Any ideas on what I should try next? Thanks in advance.
I added some code to my answer to show what the init method should look like. You should *not* set sound1=nil inside the IBAction method itself. That will defeat the purpose of calling [sound1 release]. I hope this helps. You may find it beneficial to read some articles about memory management and object lifecycles in Objective-C. I'll see if I can find some relevant links.
e.James
Here's one: Cocoa Dev Central (http://www.cocoadevcentral.com/). Excellent tutorials on everything Cocoa and Objective-C related, and a great-looking site to boot.
e.James
Okay, I added the init method to set sound to nil, and removed the code that set the sound to nil inside the IBAction, and still, on the 3rd press I get a memory leak. From the AVAudioPlayer... groan. Any further suggestions? Thanks for your help.
I'm not sure. Is your 00001111ViewController class derived from antoher class? i.e. In 00001111ViewController.h, do you have a line that reads: "@interface 00001111ViewController : SomeOtherClass"?
e.James
My @interface code is the following: @interface 00001111ViewController : UIViewController{
Hmm... Perhaps we're going about this the wrong way. I'll post another suggestion in my answer
e.James
+1  A: 

I'm new to the iPhone SDK too ( and gc-less programming in general ); I've found Clang/LLVM very useful...here's the guide I used:

http://www.oiledmachine.com/posts/2009/01/06/using-the-llvm-clang-static-analyzer-for-iphone-apps.html

agentj0n
A: 

The first answer points out a static analyzer, which is definitely a good thing to use. Another good thing to use is a dynamic analyzer, which watches allocations/deallocations and memory accesses at runtime. Valgrind is a popular open source dynamic analyzer that's commonly found on Linux.

Valgrind can work on OSX (though it says it's "unsupported and incomplete and buggy"), and with a little hacking someone got it to work on iPhone SDK executables.

Even better you can try Instruments, which is part of XCode. There's a tutorial for running it here.

Jared Oberhaus
A: 

Hi eJames, so yes, there is still a memory leak. On the 3rd press

Amanda
Have you tried placing the [AVAudioPlayer alloc] methods into viewDidLoad, as I posted on the latest update to my answer? Long-distance debugging is hard :)
e.James
Yes I did and unfortunately after the 3rd press, a memory leak is found. It's strange that there's still a memory leak because in theory what you said should have done the trick, Recently I added buttons that just play a sound to check if it really was just sound that was causing the memory leak and sure enough it was.
Amanda