Friday, 15 June 2012

ios - Xcode Disposing memory - images taking up too much memory and won't deallocate -



ios - Xcode Disposing memory - images taking up too much memory and won't deallocate -

updated:

i have lot of view controllers , app image heavy. each presented modally @ moment. i'm disposing of images,timers etc , whatever else in viewwilldisappear on every view controller, when segues seems allocating memory continually on top of previous vc , else without getting rid of single thing crashes (i know happen modal segues). how can alter this? have tried embedding controllers in navigation controller same problem still happening not release of images on controllers. here illustration of code , i'm getting rid of i've created in vwd. vwd beingness called. makes sense someone, in advance.

@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 within -(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) { }]; } //======================================= 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 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]; }

several things.

if nowadays view controllers modally, stacked 1 on top of next, , none of them released until dismiss them. create sure you're not creating new instance of previous view controller , pushing modally instead of dismissing desired vc.

second,

it used when view controller moved off-screen, it's view hierarchy unloaded, freeing of memory took. that's no longer true. (and hasn't been quite few major ios releases. want changed in ios 4, not positive of this.)

if view controller in memory, it's entire view hierarchy, including images installed in image views within views.

you can indeed implement viewwilldisappear method , utilize method nil out info structures not installed in view hierarchy. need implement viewwillappear method reloads info structures.

if app presents series of view controllers modally, , user "unrolls" each view controller , returns root view controller method of using modal presentation reasonable. (using navigation controller , stack of pushed view controllers might better, claim not.) both approaches maintain stack of visited view controllers active , in memory.

if instead ux has user move vc vc without need return, should instead implement own custom segue dismisses previous view controller, or perhaps uses kid view controller swaps 1 user navigates.

ios objective-c xcode memory modal-dialog

No comments:

Post a Comment