views:

298

answers:

2

When, I run my application in the simulator using the Leaks instrument, it uses about 2.5mb of memory. When I run it on the iPhone, it takes forever to launch, slowly climbs to ~34mb of memory and then crashes. However, when I run it on the iPhone without Leaks, it launches quickly and runs fine. Why is this?

A: 

The crashes are probably due to the memory leaks you have in your app and the device running out of memory. Without seeing any code it is impossible to tell. Here is a tutorial on how to use instruments

The "takes forever to launch" and and runs slowly is due to the leaks monitoring system polling the device every 10 seconds for information

EDIT: It is probably due to keeping too many objects alive in memory at a given time. Check instruments and Object Allocations. Just because you have no leaks doesnt mean you can't run out of memory

coneybeare
Unlikely -- the developer's app only grows significantly when running under instruments. This indicates that debugging code is in play that is causing the growth. Most likely, zombie detection is the cause.
bbum
When i run Leaks with the simulator, there are no memory leaks. There were a few but I fixed them all
rickharrison
I edited my answer
coneybeare
+1  A: 

Do you have zombie detection enabled?

Zombie detection will cause every object allocated to never be deallocated (the object is marked as a zombie on deallocation). This will cause memory growth as you describe. A common mistake is to leave zombie detection enabled when using Instruments, either through environment variables or through the checkbox in the Object Alloc instrument.


If it isn't zombies or leaks, then it is -- as others have said -- memory being allocated and sticking around. Use the Object Alloc instrument to track the objects allocated in your application and make sure that every single one of them exists for a reason. You can turn on "only track live allocations" to filter out all the objects that have already been deallocated.

bbum
Zombies will cause the app to grow in ALL environments, not just debug
coneybeare
How can I see if i have zombie detection enabled?
rickharrison
Click on your Executable file in xcode. Look under arguments. If it says NSZombieEnabled and has a checkmark, then it is on
coneybeare
Not if you have zombies enabled for running on the device, but not on the desktop. :) (I've done this to myself.)
bbum
I do not have NSZombieEnabled on. When I run leaks with the iPhone there are no leaks. Just gradually uses up a ton of memory and then crashes
rickharrison