views:

2763

answers:

3

I'm afraid I introduced a memory leak or something to version 1.2 of my iPhone app. When I use 1.2 version I notice that my battery drains a lot quicker then with 1.1 version. For comparison, with 1.1 version the battery would last whole day and still have plenty of juice in the evening but with 1.2 I find that I have to plug it in mid afternoon.

Would a memory leak (or a lot of them) cause an increased battery drainage, or do I have something else going on?

The only interesting thing my app uses is AVAudioPlayer class to play some caf audio files. Other than that it's just couple of views with a table view.

I do call AudioSessionSetAcvie(false) in my applicationWillTerminate method, so I don't think it's the audio session that's causing this. I don't have to have my app active for the battery to get drained. It's enough to use it for a while and then exit. So I'm pretty sure I'm leaving something behind, I'm just not sure what.

I tried playing with Instruments tool, but it looks like you can't used with the app running on the device (for some reason my app stopped working in the Simulator)

Any ideas on how to go about finding what's causing the battery to drain?

+3  A: 

Memory leaks will not cause increased battery usage. However, if a memory leak persists, eventually you will get a memory warning, and if you can't clean up enough memory, your application will be killed.

Increased battery utilization usually means something is causing your code to continue running. The best way to tackle this problem is to run your application under Instruments (with Sampler probably) and let it sit there in the state that you're confident it usually runs the battery down. Inspect the results of Sampler, and if you have code running, you'll be able to see the stack trace for it.

Hopefully once you've located what code is running, it will become apparent how to stop it.

NilObject
I notice the battery draining even when my app is not running. So is it possible that some parts of my app are still executing even when I exit my app?
subjective-c
I highly doubt it. So you're noticing a faster battery drain when comparing a freshly booted phone to a freshly booted phone after quitting your application?
NilObject
Right. But I don't have any hard evidence, just my observation. I'm beginning to think now that it's not related to my app.
subjective-c
+1  A: 

Memory leaks won't cause increased battery usage, as Nilobject says.

I would try commenting out various areas of functionality, one at a time, to try to narrow down the area that is causing the problem. In your case, the first thing to try is obviously to remove the audio. If, once you've done that, battery usage is back to normal, you know where to look more deeply.

Jane Sales
A: 

(for some reason my app stopped working in the Simulator)

I would fix that and use instruments to fix the performance bug. It's never a good idea to fix the difficult defect and leave the easy one.

Roger Nolan
I don't really feel like spending time debugging Apple's Simulator. The damned thing never really worked well for me, so I stopped using it. I develope with iPhone connected.
subjective-c