开发者

Xcode crash level=1 + 2 without potential leaks (maybe because of animation)

First of all i am a n00b. After long time of trying and research i decided to get some external help. My Project: i made a book for children. After i analyzed the code I got rid of all potential leaks, but still i have a Level=1+2 crash. with testing my app i figured out that my animations could be the probleme because after flipping through the book and watching around 30 animations it crashes.

Did i forget to release something? maybe you see something i don´t see. Here is my Code

- (void)addButton1 {
    UIButton *button1 = [UIButton buttonWithType:UIButtonTypeCustom]; 
    [button1 setFrame:CGRectMake(174, 100, 421, 250)];
    [button1 setBackgroundImage:[UIImage imageNamed:@"button.png"] 
                   forState:UIControlStateNormal];
    [button1 addTarget:self action:@selector(buttonPressed1)
      forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:button1];
}

- (void)animieren1:(UIImageView *)image {
    [self animationZustand1];
    [UIView commitAnimations];  
}

- (void)buttonPressed1 {
    [self animieren1:self.animation1];
}


- (void)normalZustand2 {
    [self.animation2 setImage:[UIImage imageNamed:@"muller3s.png"]];
}

- (void)initAnimation2 {
    animation2 = [[UIImageView alloc] initWithFrame:
                   CGRectMake(173, 550, 422, 262)];
    [self normalZustand2];
    self.animation2.opaque = YES;
    [self.view addSubview:self.animation2];
}   

- (void)animationZustand2 {
    NSArray *imageArray = [[NSArray alloc] initWithObjects:
                       [UIImage imageNamed:@"muller3s.png"],
                      开发者_如何学Python [UIImage imageNamed:@"muller4s.png"],
                       nil];    
    self.animation2.animationImages = imageArray;
    self.animation2.animationDuration = 2.1;
    animation2.animationRepeatCount = 1;
    [self.animation2 startAnimating];
    [self normalZustand2];
     [imageArray release];

    NSString *path = [[NSBundle mainBundle] pathForResource:@"riesel" ofType:@"mp3"];
    AVAudioPlayer* theAudio = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL   
    fileURLWithPath:path] error:NULL];
    theAudio.volume = 0.1;
    self.audioPlayer3 = theAudio;
    [theAudio play];
    [theAudio release];
}       

Any ideas? It would be really cool if anyone could help me! Thanks in advance Planky


It sounds like you're unclear what a 'level 1' crash is. The levels refer to memory warnings - your application receives notifications from the system when you're close to exhausting your app's memory allocation.

Your app should respond to these notifications by clearing out objects it's not using any more - if you don't, you'll receive more warnings, until your app is terminated by the system since there's simply no more memory to provide you.

Whilst memory warnings can be caused be leaks, this is typically not the root problem. In the overwhelming number of cases they are instead caused by trying to load too many raw assets into memory at the same time.

You will need to take a hard look at your code and structure to figure out the best way to cope with this. Perhaps currently you're just loading all 30 pages of your book into memory at the same time: you need to think about loading in resources as they are needed. If an asset isn't visible to the user, perhaps you could remove it from memory and reload it when needed.

It's also important in graphically rich apps to remember that file size doesn't equal the size the image takes up in memory. Suppose you have a PNG file the size of the iPad screen (1024x768). When loaded into memory, this image will take up over 3 megabytes of memory. All iOS devices are memory constrained, some more than others: on a first generation iPad that single image could have used up 5% of your total memory allocation (the exact amount your app has access to varies and depends on many factors: hence why you receive notifications when you're nearing the limit).

Memory warnings are one of the more 'friendly' crashes, because iOS will try to tell warn your app before they happen. So it's very important you listen out for these notifications in your controllers, and respond accordingly.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜