iPhone memory leaks with store kit - iphone

I am trying to develop an application which uses storekit api. The document (Store Kit guide) suggests that the api will not work on a simulator. I found out that memory leaks will not be able to work on a device. I was wondering if any one can tell me how to check for memory leaks while using a store kit api on a project?
How is it possible?

You can use instruments with the device to find memory leaks. See Does Instruments (ObjectAlloc/Leaks) require the simulator?

Related

How to find memory allocations and leaks in iphone applications without using instruments?

I am planning to create a iPhone/ipad application which can check for allocations and leaks of the applications available on the device. Currently i don't know whether there are any existing API's(which may be private since am not planning to submit it to app store) for achieving this.My thought may be bit crazy but can anyone lemme know whether it's feasible or not.
iOS applications are sandboxed -- one app can't look at the memory or resources of another. So there's no way you're going to be able to write an app that detects leaks in other apps. The story may or may not be different if you're willing to jailbreak your device, but finding information in that case will prove difficult.
Update 1: (got your question wrong!)
Analyzing other apps within a iOS app is not possible on un-jailbreaked phones (sandboxing).
If you can do a jailbreak, try to compile valgrind on iOS (very hard!) and build a GUI (iOS app) around it.
if you search leaks in your app (different question):
For memory leaks you don't need API's.
I would recommend you...
... use ARC.
... use valgrind (popular c instrumentation framework) for iOS (simulator only).
When you find and fix leak in the simulator, the chance is >99.9% that they are also fixed on iOS device builds.
But why not using Instruments?

Strange memory leaks when running 'Navigation Based Application' template project

I did a very simple test which was creating a blank project using xCode and execute on device. When executed with Instruments I got memory leaks !
Please note that I am using iPhone 3G device running iOS 4.0.2
Here are the steps to reproduce:
From xCode 3.2.3 Choose File -> New Project -> Navigation-based Application selecting Use Core Data for storage
Choose Device - 4.0 as the build Target
Choose Run -> Run with performance tool -> Leaks
On the iPhone 3G device (running iOS 4.0.2) click the '+' button several times in the launched App.
Here is the Instruments screenshot:
Can anyone confirm this issue?
Thanks,
Joshua
It looks like you're getting leaks related to WebKit (WebCore, JavaScriptCore, etc.). I had the exact same leaks in a few of my projects with iOS 4.0, but the apps still got approved by Apple (because the leaks are not your fault).
The good news? I recently tested these same apps with the 4.1 SDK, and all of my WebKit-related leaks are gone! Since you are using 4.0 I suggest you try the 4.1 SDK to see if they've disappeared.
Cocoa has always had very small leaks in it, and it occasionally has things that look like leaks and aren't really. When looking for leaks, what you are looking for are leaks that grow over time. Seeing a single leak report like this of a few kB is not a cause for concern. If you're running this on the empty template project from Apple, you should open a radar (bugreport.apple.com), since it means that there either is a small but common leak in Cocoa or Instruments is wrong. In either case, it should be fixed, but it's not something to lose sleep over.

enabling guard malloc for Iphone device or for store kit api?

I am using store kit api for an application on iphone. I would like to know if it is possible to enable Malloc Guard while running on the device and see if there are any memory leaks. Could someone let me know if it is possible?
This page doesn't mention it is possible, quoting:
You can use this option both Mac OS X applications and also for iPhone applications running in the simulator.
So I guess it's a no-go on the device.

iPhone: How to fix a legacy iPhone app which has really bad memory management? unittesting?

I recently inherited an iPhone app. The original developer did not understand memory management and well the app works in simlulator but not in on old iPhone (lots of crashses). Do you have any thoughts on the process by which I can save the app?
Can I utilize or create any unittest to find memory leaks and make the process 'scientific'?
Thanks
Yes! Use Clang! Here is a good tutorial showing the benefits: http://iphonedevelopment.blogspot.com/2009/02/clang-static-analyzer.html
However, it should be installed if you have a newer SDK.
Since the Clang Static Analyzer is now built-in to Xcode on Snow Leopard, it's trivial to use it. Select Build -> Build & Analyze to see any memory problems Clang detects (hint: it will find pretty much all of them).

Core Data Instruments for the iPhone

I'm trying to monitor my core data usage but all the Core Data instruments are greyed out in Instruments. It's also not available from the "Run with Performance Tool" in Xcode. It says that the Core Data instruments are for the Mac and it's not available on the iPhone, but I've heard people talking about using it, and it's mentioned in the Apple docs too.
How can I get them working?
Thanks!
You can run Core Data instruments against the simulator only, not the device.
Open Instruments and select the Core Data items you want, then use Instruments to launch the simulated iPhone app, instead of launching from Xcode.
Hopefully this support is better in future versions. Also, I believe it only works with 3.1, not 3.0.