When testing an iPhone application, is it enough to just use the Leaks instrument?
Asked Answered
I

6

10

I am about to finish my first iPhone application, and I'm am wondering if there are a set of steps that are used to check the app for memory leaks, performance, etc.?

Is checking with the Leaks instrument enough?

Are there any series of tests that need to be run? Is there any tutorial/document that you guys can point me to?

Irritant answered 9/12, 2010 at 12:7 Comment(1)
B
3

Testing with the Leaks instrument should be part of your strategy, but not all of it. You will want to test your application from multiple angles.

My strategy towards testing tends to focus first on functional testing, followed by performance tests, and then a last round of functional tests. There's very little point in tuning performance if you have a crashing bug somewhere in your code, unless that crash is due to resource exhaustion of some kind.

Hammer on the application to try and make it break by running through every option under every condition you can think of. If that passes, I usually employ my "crazy monkey on crack" test where I hammer random buttons and areas on the screen as fast as I can to see if I expose any further crashers.

Only then do I turn to Instruments. Run the application on the device (no performance tuning should ever be done in the Simulator) using the Time Profiler and Memory Monitor instruments. Look for both performance hotspots and memory spikes, as well as memory accumulations. Repeat the same sort of testing you used for functional issues earlier while doing this.

Once you deal with the hotspots and obvious buildups, you can step down to a finer-grained examination of memory. I actually prefer using the Object Allocations instrument with its new heapshot analysis capability to the Leaks instrument for finding subtle memory buildups and leaks. The Leaks instrument tends to be conservative, and can miss some buildups. Nathaniel points out Bill Bumgarner's excellent post on the subject.

The Object Allocation instrument and its heapshots are particularly powerful when combined with the UI Automation instrument, where you can do hundreds or thousands of cycles of testing within parts of your application to make even the tiniest memory accumulation stand out. I've started to do more of this kind of testing now.

I think it works best to see this in action rather than described in text, so I'd recommend watching the video for my "Testing" and "Performance tuning" classes as part of my advanced iOS course on iTunes U. I demonstrate each of these tools and how I use them in the testing of my own applications before App Store submission. My course notes (in VoodooPad format) also describe this in detail.

Branny answered 10/12, 2010 at 23:37 Comment(1)
wow! that's very helpful, thanks a lot brad - i am gonna look at the links you ahve mentioned.. Thanks a lot once againIrritant
M
4

Running with "Leaks" is important. I'm not aware of a tutorial/checklist for final testing, though something like that would be handy. A couple things I would add:

1) Be sure to test with actual hardware and not just the simulator to make sure that performance is reasonable on ALL hardware you intend to support. In my experience, the simulator does not give you an accurate feel for the performance of the device and there can be significant differences between older and newer hardware (the extreme example being iPhone 4 vs. Gen1 iPhone). For example, in one of my apps, I generate a 1-page PDF report. On iPhone 4 and even iPad, it takes about 1 second. On Gen1 iPhone, the same code takes close to 8 seconds. There wasn't much I could do to speed it up, but it was clear I needed to add a progress indicator to let the user know that the app was not frozen. This is something I would not have noticed running with just the simulator and/or the latest hardware.

2) You might want to spend a little time running with NSZombieEnabled. This can find memory issues that may be lurking behind the scenes even if there is currently no visible sign of trouble. More information:

http://www.cocoadev.com/index.pl?NSZombieEnabled

Moua answered 9/12, 2010 at 13:20 Comment(1)
I understand what you meant cbranch, i have already had nszombie enabled in my project, things look fine - but i think i will just do each and every possible test to try my best not to get rejected by appleIrritant
B
3

Testing with the Leaks instrument should be part of your strategy, but not all of it. You will want to test your application from multiple angles.

My strategy towards testing tends to focus first on functional testing, followed by performance tests, and then a last round of functional tests. There's very little point in tuning performance if you have a crashing bug somewhere in your code, unless that crash is due to resource exhaustion of some kind.

Hammer on the application to try and make it break by running through every option under every condition you can think of. If that passes, I usually employ my "crazy monkey on crack" test where I hammer random buttons and areas on the screen as fast as I can to see if I expose any further crashers.

Only then do I turn to Instruments. Run the application on the device (no performance tuning should ever be done in the Simulator) using the Time Profiler and Memory Monitor instruments. Look for both performance hotspots and memory spikes, as well as memory accumulations. Repeat the same sort of testing you used for functional issues earlier while doing this.

Once you deal with the hotspots and obvious buildups, you can step down to a finer-grained examination of memory. I actually prefer using the Object Allocations instrument with its new heapshot analysis capability to the Leaks instrument for finding subtle memory buildups and leaks. The Leaks instrument tends to be conservative, and can miss some buildups. Nathaniel points out Bill Bumgarner's excellent post on the subject.

The Object Allocation instrument and its heapshots are particularly powerful when combined with the UI Automation instrument, where you can do hundreds or thousands of cycles of testing within parts of your application to make even the tiniest memory accumulation stand out. I've started to do more of this kind of testing now.

I think it works best to see this in action rather than described in text, so I'd recommend watching the video for my "Testing" and "Performance tuning" classes as part of my advanced iOS course on iTunes U. I demonstrate each of these tools and how I use them in the testing of my own applications before App Store submission. My course notes (in VoodooPad format) also describe this in detail.

Branny answered 10/12, 2010 at 23:37 Comment(1)
wow! that's very helpful, thanks a lot brad - i am gonna look at the links you ahve mentioned.. Thanks a lot once againIrritant
V
2

The Leaks instrument catches many possible leaks, but not all. Observe your total memory allocation and make sure it declines when it's supposed to. Read bbum's heapshot analysis case study:

http://www.friday.com/bbum/2010/10/17/when-is-a-leak-not-a-leak-using-heapshot-analysis-to-find-undesirable-memory-growth/

And run the Clang static analyzer, via the Build and Analyze command, if you haven't been doing so from the getgo.

Virtual answered 10/12, 2010 at 23:4 Comment(0)
E
1

You should simulate low memory for your app to see how it reacts, its not so fun to get killed by iOS because you are consuming too much memory. If you develop only on a simulator its easy to miss since its seems quite forgiving when it comes to memory.

Executory answered 9/12, 2010 at 13:29 Comment(1)
Thanks for the tip Anders, will do that right away - i hope no surprises :)Irritant
H
0

Just make sure you release the objects whenever it is necessary to reduce memory leaks

Check this link to know about instruments.

http://developer.apple.com/library/mac/#documentation/DeveloperTools/Conceptual/InstrumentsUserGuide/Introduction/Introduction.html

Hornsby answered 9/12, 2010 at 12:17 Comment(2)
Thanks BuildSucceeded, i will go through the documents and see what i can find :)Irritant
Just make sure that your App comes out of instruments with nil leaks and no crashes. Thats it you are good to go.Hornsby
M
0

First of all build your app but don't it, now click on the "Run" on the top menu bar of the XCode and then click "Run With Performance Tool" and select "Leaks". You will see the new window where u will be able to see the Live Bytes used by your app and where memory is leaking. Memory leaks will be shown by red mark. If find any problem while doing this, feel free to ask.

Maccabean answered 9/12, 2010 at 12:23 Comment(1)
hi there, as i mentioned in my post, i have already done with Memory leaks and everything looks fine, i am wondering if there is more that i need to doIrritant

© 2022 - 2024 — McMap. All rights reserved.