Previously in Use The Right Tool For The Job, I posted about using memory profiling tools on Windows to find those insidious memory leaks and unwanted allocations in your Windows Phone games. That post was written right around the time that the Mango update was being released and along with it were the new Performance Analysis tools in the Windows Phone SDK. I tried using the PA tools in the beta version of the SDK and found them quite limited… at that time. I have recently been enlightened to their usefulness, and now I can say that sometimes the right tools are right under your nose.
In a recent AppHub forum thread, Pratap Lakshman from the Windows Phone Tools team at Microsoft responded with links to several detailed blog posts about using the PA tools to do memory profiling on the device. With my previous experience using the PA tools and having written the previous article, of course I suggested using Windows memory profiling tools to find the memory leaks. With Pratap’s response, I decided to investigate the current state of PA tools on devices that had been updated to Mango and see how they fared.
To say I was surprised was a bit of an understatement. Here are some tools that I had dismissed fairly early as being of limited use to XNA projects, but here it was showing me the information I needed to track down nearly every memory leak and excessive allocation and it was running in the app’s native environment on the device. Have a read of the Windows Phone Developer Blog articles I have linked at the end of this post to see many of the wonderful features offered by the PA tools. The memory profiling tools on Windows are very comprehensive, and can offer some details that the PA tools simply don’t offer. ANTS Memory Profiler is still a great tool and its visualization of the hanging object references is second-to-none. There are some things that can only be found by profiling in the app’s native environment however, and not all projects are suitable for porting to Windows along with the time and effort it can take to create that Windows port if you didn’t already have it.
I have suggested some improvements to Pratap that hopefully they will take into consideration for future updates. The most useful of these I would consider to be the ability add custom markers in the code to flag certain events, such as loading a level, returning to the main menu, etc. At present all you see is a long timeline of memory allocations with no indication of at what point along that timeline certain game events happened. Since you can only profile from the beginning of app execution and you may only be interested in a section that happens during gameplay, it can be difficult to find the relevant section of the timeline. Some allocation patterns give away certain stages of the game, such as a steadily rising total allocation is usually an indication of loading a level, and hopefully a horizontal section of the timeline (that is, no allocations) is your gameplay segment. Having the ability to add custom markers via an API would call out the areas you are interested in immediately and you can get on with the job of finding those problem allocations.
With the Windows Phone 8 SDK just around the corner, it will most likely bring a whole new set of tools. Whether those tools will also be usable on Windows Phone 7.5 (and 7.8 when it is released) will remain to be seen. I would like to thank Pratap Lakshman and the rest of the Windows Phone Tools team for providing a great set of tools in the Windows Phone SDK, and I am keen to see what new goodies they will be providing in the new SDKs.
Links to the blog posts for memory profiling with the PA tools.