iphone app sporadically hangs for a few seconds - iphone

When I run my Iphone app on my Ipod touch, it runs fine most of the time. But every so often, it will hang for a short while -- anywhere from 5 to 15 seconds. After the hang, it resumes running normally.
The strange thing is that to all appearances, the app's demands on the system should be fairly steady. It is doing a lot of dragging stuff around with calls to TouchesMoved. But it drags a maximum of two labels at a time.
How might I go about tracking down such a problem?

A good start would be to run your app under Shark to see where it is spending most time during those periods.

Related

CCRepeatForever not resuming immediately after sleep

In a cocos2D powered iphone app, I use the CCRepeatForever action to make the background pass by. It works fine when I debug the app (build and run via XCode). Even if I quit the app and resume it, no problem.
However when I bundle the app into an .ipa for beta testing I get a weird problem :
At launch the background passes by nicely. But if I quit the app and resume the game later, the app takes me back where I left it, with everything working but the moving background. And after a time (roughly proportional to the time since I quitted the app) the background starts moving again as it should, without me doing anything particular.
Is this a know issue ?
Thanks
OH, I had a very similar problem a little while ago. I would pause the game, then on resume nothing would happen, then it would suddenly jump and I'd be swarmed with monsters.
I can't tell you precisely where to look, but here's what I was doing:
I had a timer that was not using the (ccTime)dt to calculate time, but was using an NSDate timestamp. The problem was that I had an event to be scheduled at a certain time based on the date, but was using the dt to figure out when to trigger the event.
As far as I could tell, pausing the game was halting the scheduled events, so the "dt" wasn't incrementing at all, but the system clock kept ticking, so what ended up happening is that I would pause for say 10 seconds, the system clock ticked up and triggered, but the "dt" was adding into a float timeElapsed, and until that caught up, nothing happened.
What you probably need to look for is something inside a scheduled event that is using an NSDate or a unix timestamp or the iPad/iPod system clock. When you halt the simulator, the system clock doesn't seem to run the same way it does on an actual iPad.
Sorry, I don't know EXACTLY how this stuff works, but I also went through an agonizing time with a similar problem and it was based on the system timer. Just make sure you're pausing everything with the CCDirector properly and make sure you're not using any system clock stuff for game timing

Strange delay for touch events in UIView

I am working on an OpenGL application for the iPhone...
My app has only 2 views:
An OpenGL view and, as a subview for the OpenGL view, a view with the sole purpose of catching touch events...
The problem is that after about 10-15 minutes of keeping the app running on the device, I get a big (0.5s-1s) delay between every touchesMoved:withEvent: call
The animation runs smooth, and CPU usage is also not the problem (10% at most)
I have no idea what might be causing this
That is weird, eh.
This happens ON THE DEVICE right? When you are not running tethered from XCode?
I would guess you are using up a lot of memory, either a leak or just in some way using up more and more memory as time goes on.
Are you familiar with the various memory tools to watch what is going on?
Also, what about this: launch a few other large apps that remain in the background. Run your app until the problem exhibits. Then, kill the other apps. Does the problem suddenly go away? If so that would suggest you're low on memory.
Would be interested to hear.

iPhone app lag on startup before main

When I launch the app on my 3GS it sits on the Default.png for 4-5 seconds. I'm not sure what it is doing during this time. I placed NSLog timing statements at the top of main and didFinishLaunchingWithOptions. The NSLog statement from main does not print to the console until the moment that Default.png goes away, and the entire process from the top of main to the bottom of didFinishLaunchingWithOptions only takes 1 second.
So, what is my app doing before it starts main, and what can I do to speed that time up?
Don't start from Xcode with a debugger, that takes a lot of time. You will see that your app starts much faster when you launch it via the icon on your homescreen.
I suggest you look at your plist file and xib files (not 100% sure if root view gets loaded before or after main, but worth a shot). Also, how big is that png file? Try launching without it and see how long it takes.
Does your application do this even when there are no other programs resident in memory? The reason that I ask: since you have observed that the delay appears to happen prior to entering main(), then it is possible that iOS believes that more memory is needed in order to run your program. If there are other apps in the Suspended state, then iOS could be busy waking those apps up momentarily in order to invoke didReceiveMemoryWarning on their view controllers, and perhaps ultimately tell them to go away by calling their app delegate's applicationWillTerminate:. Perhaps this is what is taking time.
One easy test you could perform would be to completely reboot your phone and then launch your app a few times without running anything else first. After the first invokation of your app, I would expect it to start quickly (unless your app, itself, allocates a lot of memory!).
If you didn't want to reboot your phone, you could manually remove all of the apps from your multi-tasking switcher by closing each one by touching the red minus signs that you can bring up using touch-and-hold. Then run your app and see if you are still seeing the 4-to-5 second delay.

What happens before applicationDidFinishLaunching is invoked?

I'm doing performance testing on my iphone app and I'm noticing that sometimes a good 3-4 secs elapse at startup before I start seeing my NSLogs from applicationDidFinishLaunching. I've optimized what happens once the code enters applicationDidFinishLaunching but I'm not sure how to optimize what goes on before that. I'm using a Default.png splash screen so it basically just stalls on that screen before it enters applicationDidFinishLaunching and starts doing something.
Just to give you guys some context, I have no nib files and I'm using core animation, if that makes any difference. I have about 10 different controllers and my total bundle size is just under 2MBs.
Try running it without the debugger attached - one of the things it does on startup is wait to connect to your mac ;)
If you just run it in the device without your mac connected do you still see the delay?
I did some experimentation a little while back and found that default start time for most apps is 3 seconds or more.
I was annoyed that the voice memo apps took up to 10 seconds to launch by which time I had forgotten what I was going to say. I tried to write one that would launch faster and by using a default.png and starting the recording automatically I got a recorder that constantly launched in 1-1.5 seconds. To get that launch time, I had to start the recorder before the interface became active.
However, in this research I found that most apps e.g. an app compiled straight from an Xcode template without modifications, launched in 3-5 seconds.
Based on that fact, I would say you really don't have a problem. The startup time falls in the expected range. deanWombourne's observation about the debugger is most likely correct and it probably adds a second or two to your startup time.

iPhone & cocos2d - Interval Action timing problem while running in device

I'm using the cocos2d framework for various of my applications, and have run into the following problem. I have set up a few sequences of actions and CallFuncNDs, the actions have durations set up and when I run it in the iPhone simulator, it works just like I expect it to: transitions take the amount of time I set them to and they go in the correct order.
When I test it on my provisioned iPhone, it all plays out in less than one second. Correct order, timing is proportional between actions, but it's all compressed into one second.
Any one have any idea why the cocos2d animations would behave differently on a device? My code is all set up similar to the cocos2d effect demos, with the difference that I am animating a ParticleSystem and not a Sprite - though the problem still shows up with Sprites.
I have experienced similar difficulties where testing the code in the simulator, it runs flawlessly. But when moved over to the device, the timing appears to be off. I've attributed this difference to the Simulator's use of the desktop CPU and Memory, where as the device is utilizing it's physical hardware and the timing is off because of how Cocos2d processes things (frame by frame, in a 'game loop'). When you start doing a couple things, the frame rate drops and Cocos miscues ... especially when you have schedules that run extremely close to each other, or schedules that cancel themself and reschedule with different timings (in increments as low as 0.1 and below is where I've run into this the most).