更新:Xcode處置內存 - 圖像佔用太多內存,不會釋放內存
我有很多視圖控制器和應用程序是圖像沉重。每一個都是現在以模態方式呈現。我正在處理所有的圖像,計時器等等,其他任何視圖都會在每個視圖控制器上出現,但是當它繼續進行時,它似乎是在前面的VC和其他所有內容上不斷分配內存,而沒有擺脫一件事情最終崩潰(我知道這將發生在模態賽段)。 我該如何改變這一點?我試圖將我的控制器嵌入到導航控制器中,但同樣的問題仍然發生在它不會釋放控制器上的任何圖像的地方。以下是我的代碼示例,以及我擺脫在VWD中創建的內容的示例。 VWD絕對被稱爲。希望這對某人有意義,提前感謝。
@interface AnimationStartViewController()
@end
@implementation AnimationStartViewController
SystemSoundID skipintro;
-(void) viewDidLoad
{
[super viewDidLoad];
(sleep(2.5));
NSString *music=[[NSBundle mainBundle]pathForResource:@"1Animation" ofType:@"mp3"];
animationaudio=[[AVAudioPlayer alloc]initWithContentsOfURL:[NSURL fileURLWithPath:music] error:NULL];
animationaudio.delegate= (id)self;
animationaudio.numberOfLoops=-1;
[animationaudio play];
NSURL *skipintroURL = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"Click" ofType:@"mp3"]];
AudioServicesCreateSystemSoundID((__bridge CFURLRef)skipintroURL, &skipintro);
//Text Timers
text1timer = [NSTimer scheduledTimerWithTimeInterval:0.0 target:self selector:@selector(Text1show:) userInfo:nil repeats:NO];
text2timer = [NSTimer scheduledTimerWithTimeInterval:0.0 target:self selector:@selector(Text2show:) userInfo:nil repeats:NO];
text3timer = [NSTimer scheduledTimerWithTimeInterval:0.0 target:self selector:@selector(Text3show:) userInfo:nil repeats:NO];
text4timer = [NSTimer scheduledTimerWithTimeInterval:0.0 target:self selector:@selector(Text4show:) userInfo:nil repeats:NO];
text5timer = [NSTimer scheduledTimerWithTimeInterval:0.0 target:self selector:@selector(Text5show:) userInfo:nil repeats:NO];
text6timer = [NSTimer scheduledTimerWithTimeInterval:0.0 target:self selector:@selector(Text6show:) userInfo:nil repeats:NO];
text7timer = [NSTimer scheduledTimerWithTimeInterval:0.0 target:self selector:@selector(Text7show:) userInfo:nil repeats:NO];
text8timer = [NSTimer scheduledTimerWithTimeInterval:0.0 target:self selector:@selector(Text8show:) userInfo:nil repeats:NO];
logotimer = [NSTimer scheduledTimerWithTimeInterval:0.0 target:self selector:@selector(showlogo) userInfo:nil repeats:NO];
pushtimer = [NSTimer scheduledTimerWithTimeInterval:20.0 target:self selector:@selector(performthesegue) userInfo:nil repeats:NO];
//Text Timers invalidate
stoptext1timer = [NSTimer scheduledTimerWithTimeInterval:6.0 target:self selector:@selector(invalidatetext1) userInfo:nil repeats:NO];
stoptext2timer = [NSTimer scheduledTimerWithTimeInterval:6.0 target:self selector:@selector(invalidatetext2) userInfo:nil repeats:NO];
stoptext3timer = [NSTimer scheduledTimerWithTimeInterval:6.0 target:self selector:@selector(invalidatetext3) userInfo:nil repeats:NO];
stoptext4timer = [NSTimer scheduledTimerWithTimeInterval:6.0 target:self selector:@selector(invalidatetext4) userInfo:nil repeats:NO];
stoptext5timer = [NSTimer scheduledTimerWithTimeInterval:14.5 target:self selector:@selector(invalidatetext5) userInfo:nil repeats:NO];
stoptext6timer = [NSTimer scheduledTimerWithTimeInterval:14.5 target:self selector:@selector(invalidatetext6) userInfo:nil repeats:NO];
stoptext7timer = [NSTimer scheduledTimerWithTimeInterval:14.5 target:self selector:@selector(invalidatetext7) userInfo:nil repeats:NO];
stoptext8timer = [NSTimer scheduledTimerWithTimeInterval:14.5 target:self selector:@selector(invalidatetext8) userInfo:nil repeats:NO];
moveAnimationTimer = [NSTimer scheduledTimerWithTimeInterval:0.05 target:self selector:@selector(moveAnimation) userInfo:nil repeats:YES];
stopAnimationTimer = [NSTimer scheduledTimerWithTimeInterval:20.0 target:self selector:@selector(StopAnimation) userInfo:nil repeats:NO];
}
//scrolling Animation.
- (void) moveAnimation {
animation.center = CGPointMake(animation.center.x, animation.center.y -2);
}
//Stop
- (void) StopAnimation {
[moveAnimationTimer invalidate];
moveAnimationTimer = nil;
}
//====================== Text animations
//AttheGateof
-(void)Text1show:(NSTimer *)timer {
[UIView animateWithDuration:2.0 delay:0.70
options:UIViewAnimationOptionTransitionCrossDissolve
animations:^ {
Atthegateof.alpha = 1.0f;
}
completion:^(BOOL finished) {
Atthegateof.alpha = 1.0f;
}];
}
//MidnightZoo
-(void)Text2show:(NSTimer *)timer {
[UIView animateWithDuration:2.0 delay:1.75
options:UIViewAnimationOptionCurveEaseInOut
animations:^ {
MidnightZoo.alpha = 1.0f;
}
completion:^(BOOL finished) {
MidnightZoo.alpha = 1.0f;
}];
}
//Who lives inside
-(void)Text3show:(NSTimer *)timer {
[UIView animateWithDuration:2.0 delay:2.9
options:UIViewAnimationOptionCurveEaseInOut
animations:^ {
Wholivesinside.alpha = 1.0f;
}
completion:^(BOOL finished) {
}];
}
// Thedeepblackblue
-(void)Text4show:(NSTimer *)timer {
[UIView animateWithDuration:2.0 delay:3.3
options:UIViewAnimationOptionCurveEaseInOut
animations:^ {
Thedeepblackblue.alpha = 1.0f;
}
completion:^(BOOL finished) {
}];
}
//unlockthegate
-(void)Text5show:(NSTimer *)timer {
[UIView animateWithDuration:2 delay:7
options:UIViewAnimationOptionCurveEaseInOut
animations:^ {
Unlockthegate.alpha = 1.0f;
}
completion:^(BOOL finished) {
}];
}
//tocomeinside
-(void)Text6show:(NSTimer *)timer {
//music 'high' point
[UIView animateWithDuration:2 delay:7.5
options:UIViewAnimationOptionCurveEaseInOut
animations:^ {
Tocomeinside.alpha = 1.0f;
}
completion:^(BOOL finished) {
}];
}
//behindeachlock
-(void)Text7show:(NSTimer *)timer {
[UIView animateWithDuration:2 delay:8.2
options:UIViewAnimationOptionCurveEaseInOut
animations:^ {
Behindeachlock.alpha = 1.0f;
}
completion:^(BOOL finished) {
}];
}
//something hides
-(void)Text8show:(NSTimer *)timer {
[UIView animateWithDuration:2 delay:8.7
options:UIViewAnimationOptionCurveEaseInOut
animations:^ {
Somethinghides.alpha = 1.0f;
}
completion:^(BOOL finished) {
}];
}
//======================================= Get rid of text
//indvalidate 1
-(void)invalidatetext1 {
[stoptext1timer invalidate];
stoptext1timer = nil;
[UIView animateWithDuration:0.7 delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{
Atthegateof.alpha = 0;
} completion:^(BOOL finished) {
[Atthegateof removeFromSuperview];
} ];
}
//invalidate 2
-(void)invalidatetext2 {
[stoptext2timer invalidate];
stoptext2timer = nil;
[UIView animateWithDuration:0.7 delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{
MidnightZoo.alpha = 0;
} completion:^(BOOL finished) {
[MidnightZoo removeFromSuperview];
} ];
}
//invalidate 3
-(void)invalidatetext3 {
[stoptext3timer invalidate];
stoptext3timer = nil;
[UIView animateWithDuration:0.7 delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{
Wholivesinside.alpha = 0;
} completion:^(BOOL finished) {
[Wholivesinside removeFromSuperview];
} ];
}
//invalidate 4
-(void)invalidatetext4 {
[stoptext4timer invalidate];
stoptext4timer = nil;
[UIView animateWithDuration:0.7 delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{
Thedeepblackblue.alpha = 0;
} completion:^(BOOL finished) {
[Thedeepblackblue removeFromSuperview];
} ];
}
//invalidate 5
-(void)invalidatetext5 {
[stoptext5timer invalidate];
stoptext5timer = nil;
[UIView animateWithDuration:0.75 delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{
Unlockthegate.alpha = 0;
} completion:^(BOOL finished) {
[Unlockthegate removeFromSuperview];
} ];
}
//invalidate 6
-(void)invalidatetext6 {
[stoptext6timer invalidate];
stoptext6timer = nil;
[UIView animateWithDuration:0.75 delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{
Tocomeinside.alpha = 0;
} completion:^(BOOL finished) {
[Tocomeinside removeFromSuperview];
} ];
}
//invalidate 7
-(void)invalidatetext7 {
[stoptext7timer invalidate];
stoptext7timer = nil;
[UIView animateWithDuration:0.75 delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{
Behindeachlock.alpha = 0;
} completion:^(BOOL finished) {
[Behindeachlock removeFromSuperview];
} ];
}
//invalidate 8
-(void)invalidatetext8 {
[stoptext8timer invalidate];
stoptext8timer = nil;
[UIView animateWithDuration:0.75 delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{
Somethinghides.alpha = 0;
} completion:^(BOOL finished) {
[Somethinghides removeFromSuperview];
} ];
}
//=======================================
-(void)showlogo {
[UIView animateWithDuration:2.0 delay:16.0
options:UIViewAnimationOptionCurveEaseInOut
animations:^ {
zoowhologo.alpha = 1.0f;
}
completion:^(BOOL finished) {
zoowhologo.alpha = 1.0f;
}];
}
-(void)performthesegue {
[self performSegueWithIdentifier:@"pushgototitle" sender:nil];
}
- (void)didReceiveMemoryWarning
{
}
- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
NSLog(@"viewilldisappear was called");
[animationaudio stop];
[text1timer invalidate], text1timer=nil;
[text2timer invalidate], text2timer=nil;
[text3timer invalidate], text3timer=nil;
[text4timer invalidate], text4timer=nil;
[text5timer invalidate], text5timer=nil;
[text6timer invalidate], text6timer=nil;
[text7timer invalidate], text7timer=nil;
[text8timer invalidate], text8timer=nil;
[stoptext1timer invalidate], stoptext1timer=nil;
[stoptext2timer invalidate], stoptext2timer=nil;
[stoptext3timer invalidate], stoptext3timer=nil;
[stoptext4timer invalidate], stoptext4timer=nil;
[stoptext5timer invalidate], stoptext5timer=nil;
[stoptext6timer invalidate], stoptext6timer=nil;
[stoptext7timer invalidate], stoptext7timer=nil;
[stoptext8timer invalidate], stoptext8timer=nil;
[logotimer invalidate], logotimer=nil;
[pushtimer invalidate], pushtimer=nil;
[moveAnimationTimer invalidate], moveAnimationTimer=nil,
[stopAnimationTimer invalidate], stopAnimationTimer=nil;
AudioServicesDisposeSystemSoundID(skipintro);
[Atthegateof removeFromSuperview], Atthegateof=nil;
[MidnightZoo removeFromSuperview], MidnightZoo=nil;
[Wholivesinside removeFromSuperview], Wholivesinside=nil;
[Thedeepblackblue removeFromSuperview], Thedeepblackblue=nil;
[Unlockthegate removeFromSuperview], Unlockthegate=nil;
[Tocomeinside removeFromSuperview], Tocomeinside=nil;
[Behindeachlock removeFromSuperview], Behindeachlock=nil;
[Somethinghides removeFromSuperview], Somethinghides=nil;
[topper removeFromSuperview], topper=nil;
[skip removeFromSuperview], skip=nil;
[zoowhologo removeFromSuperview], zoowhologo=nil;
[animation removeFromSuperview], animation = nil;
[stopanimation removeFromSuperview], stopanimation = nil;
}
- (void)viewDidDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
[self.presentingViewController dismissViewControllerAnimated:YES completion:nil];
}
- (IBAction)skipintro:(id)sender {
AudioServicesPlaySystemSound(skipintro);
[animationaudio stop];
[pushtimer invalidate];
[self performSegueWithIdentifier:@"pushgototitle2" sender:self];
[self.presentingViewController dismissViewControllerAnimated:NO completion:nil];
}
你調用的'viewWillDissapear'方法嗎?請發佈代碼,我們可以幫助 – 2014-10-29 11:28:51