ios - Objective-C memory issue with performSelector and infinite loop -


i'm working on project in have try executing given method given time (see automatic mode) , if auto mode doesn't succeed, switch manual mode. warn you, i'm quite new objective-c , ios dev, error might obvious.

so far, here i've done :

-(void)viewdidload {       [self performselector:@selector(automode) withobject:nil afterdelay:1.0];       [self performselectorinbackground:@selector(switchmanualmode) withobject:nil];   }   -(void)automode {       @autoreleasepool {           while (isautomode == true) {               if ([session isrunning])                   [self captureimage];                   // nslog(@"test");        }       }   }    -(void)switchmanualmode {     [nsthread sleepfortimeinterval:2.0f];     isautomode = false;     self.button.enabled = true;      uialertview* alert = [[uialertview alloc] initwithtitle:@"changement de mode"                                                     message:@"du un délai trop long, la capture automatique va être desactivée. la capture se fait maintenant de manière manuelle touchez l'écran pour prendre une photo."                                                    delegate:nil                                           cancelbuttontitle:@"ok"                                           otherbuttontitles:nil];      [alert show]; } 

i have couple issues here:
- first 1 memory used peak , app crashes.
- second 1 switchmanualmode never called.

i've tried print "test" in logs (instead of call function "captureimage"), , when that, fine.

i can't post code of captureimage, method tries image avcapturesession, , somme processing on it.
anyway, don't understand why switchmanualmode called in case , not in other.

one reason put @autoreleasepool @ wrong place. should inside loop. running infinite loop within the same autorelease pool; that's asking out of memory problems. capturing images @ highest possible rate doesn't help.

the other problem performselector run on main thread, second performselector won't called, since first call never returns.

you should really, rid of performselector , switch gcd. wouldn't want see performselector , sleep calls in code written today.


Comments