iOS: ¿qué puede causar un aumento repentino en el uso de la CPU?

My game will be using 2 - 6% when I'm observing in instruments, then suddenly it hikes up for half a moment to something higher, and then a short time later it will hike up to 118% and everything will stop working for good. Do you know what can cause this? The memory being used is all within reason, and there is no sudden hike in memory.

ETA: OK I figured out the problem. I had this method:

self.objectSprite.animationImages = [NSArray arrayWithObjects:
                                     [UIImage imageNamed:@"assistant1.png"],
                                     [UIImage imageNamed:@"assistant2.png"],
                                     [UIImage imageNamed:@"assistant3.png"],
                                     [UIImage imageNamed:@"assistant4.png"],
                                     [UIImage imageNamed:@"assistant3.png"],
                                     [UIImage imageNamed:@"assistant2.png"],
self.objectSprite.animationDuration = .7;
self.objectSprite.animationRepeatCount = 1;
[self.objectSprite startAnimating];

[NSTimer scheduledTimerWithTimeInterval:7 target:self selector:@selector(animArray) userInfo:nil repeats:YES];

The timer at the bottom is supposed to call the method again after 7 seconds. Since the timer is created inside the method, setting "repeats:" to YES was unnecessary. I don't fully understand why, but this would suddenly hike up my CPU usage after a while. After I set repeats: to NO, it stopped.

preguntado el 13 de febrero de 14 a las 21:02

How have you determined the CPU usage goes up to 118 %? How is that even possible? -

In the activities monitor in instruments -

ok I found the problem. There was a method that set a timer, and the timer called the same method again. The "repeats:" argument should have been NO, but it was set to YES. -

Could you update the question with the root cause of the problem and self answer with the solution? -

0 Respuestas

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.