How to use Zombie while debugging iPhone application?
It's about setting up an environment variable. See the following article for details
http://www.cocoadev.com/index.pl?NSZombieEnabled
Take good care of not letting this in place because no memory will ever be free.
You can open up Instruments and choose the Zombie instrument and next your app target from the 'Choose Target' drop down menu. And use your app till it crashes this will lead you to the Zombie object that causes it to crash.
Remind not to use the Leak instrument with the Zombie one since it will show many leaks (the objects not deallocated kept in memory to test if they can be zombies in the futures) and remember it will use lots of memory so you'd better you the simulator for this task.
Related
i made an iPhone app that uses camera. It works fine in iPhone, no memory warnings at all. It is also running on iPod touch 4G but gives memory warnings and crashes after some time after getting level 2 warning.
If someone can point me the possible reason for this. Thanks.
The only way you are going to fix this is by being able to debug it on the device. I wrote this blog to explain how to debug EXC_BAD_ACCESS, which is what I assume you are getting
http://loufranco.com/blog/files/Understanding-EXC_BAD_ACCESS.html
The simplest things to do:
Run a Build and Analyze and fix every problem it finds (or at least rewrite it so that B&A doesn't think it's a problem) -- Having a clean B&A is a really good way to making sure you catch these problems early
Turn on Zombies and run your program -- this makes the last release sent to an object turn it into a zombie rather than dealloc it. Your program will leak tons of memory, but if you ever send a message to a zombie it will stop right there and you will see a bug that you need to fix, because in your real version, that would be a crash (sending a message to a dealloced object).
More techniques described at the link
It crashes on a specific operation or randomly?
if randomly,
use instrument to check your memory leaks and memory usage. It's hard to figure out where the problem lies in without going through all your app.
I'm in big trouble now, my iPhone application keep terminating again and again due to memory leaks and I am unable to judge that where are those leaks. Tell me what step can I take in order to resolve this problem.
Thanks
You can use Instruments to see where potential leaks are.
Here is a good tutorial. http://mobileorchard.com/find-iphone-memory-leaks-a-leaks-tool-tutorial/
I think you're confusing terminology here. A memory leak is when you don't release an object after you're done with it.
A leak won't directly cause a crash. Leaks can indirectly cause crashes if you run out of memory as a result of not releasing lots of objects. However, if your crashes are happening in the simulator as well this is almost certainly not the case (the simulator having far more available memory than the device). As Daniel says, you can use the instruments tool to find out what's leaking.
Another good method is to use the XCode static analyzer - you can have it analyze your code and detect most common leaks.
Now, if your app is crashing and it's not because of a memory leak (you'll be able to tell this because you'll have memory warnings outputting to the console) then chances are your problem isn't a leak. Perhaps it's a bad access (you're over releasing), in which case your instruments leaks tool isn't going to help you.
If you need to find out leaks and source of crash. you can try these
try to find as many leaks as possible from Instruments and fix
set NSZombieEnabled for your executable parameters and debug application crash
change all your autorelease objects to use alloc init as much as possible.
--
worst resort is if it keeps crashing even after trying all the above three. you write memory intensive module of your code in a thread and clean up that thread. I've noticed usually when threading is done the memory footprints are much cleaner. This is just my opinion, but the above 3 you should do.
You could also Build + Analyze your application in XCode itself (Cmd+Shft+A or Product > Analyze). It'll show you the more obvious leaks.
I have implemented ipad application foe that i want to check memory leak.I know that there is some extra feature for memory leak.but i dont know how to enable.please advice me if possible.
To check for memory leak you can run your app with the Leaks tool. To do so, go to Run > Run with Performance Tool > Leaks.
In order to get precise information about leaks, activate "Extended detail" by pressing CMD-E, and click on a leaked block.
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?
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.
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
I have built my first game using Cocos2D. It worked fine on the simulator. But when it runs on the actual iPhone, it crashes. I don know why. Thought it was memory leaks, so i tried to detect, but no leaks found. I tried to increase and decrease frame rate, neither both succeeded. Anyone experienced please help me out. I am really stressed now. If anyone had the same issue please share with me your opinion.
Yours thanksfully.
I've run into similar issues (I also use Cocos, but I don't think this is Cocos specific). The best thing to do is plug-in your iPhone and watch the stacktrace when it crashes (or retrieve the stacktrace after the fact)
This happened to me a lot because the resources between the iPhone and the simulator were not in sync; in other words, some how resources would be available to the simulator (eg: images) but those same resources were not transferred to the iPhone for whatever reason. Sometimes, if I ran 'clean' on the simulator, I would observe the same issue.
It's extremely frustrating to debug these types of issues, but you'll get used to it.
I agree with Dominic - we definitely need more information to be able to help you - do you have the output from the console or the stack from the debugger?
Also, while memory leaks are a Bad Thing, they rarely lead to crashes directly. They will increase the amount of memory used by your app so if you're memory intensive then you might get a problem but they're not the first place I'd look to try to debug this.
Try running the app in Instruments and watch the memory usage graph - then not only can you see the total that your app is using but you can get an idea of which sections of your app use the most and can focus your efforts in reducing it.
Sam
Sorry, but you need to specify more details. How does it crash? What does the error log say? One thing you might look into is the amount of memory, your game consumes. If it uses more than 64 MB on the actual device, the OS will very likely just terminate it. In the simulator on the other hand, your app might use lots more memory without a problem.
I have found tools like Instruments and NSZombieEnabled to be very helpful in tracking down issues such as these.
Without more information, I would try the following steps:
Delete the app from the device and simulator (using the tap-and-hold technique to make your icons jiggle) and reinstall it. Sometimes a setting (or lack of a setting) in the user defaults will cause a crash, and those don't get wiped out unless you delete and re-run your app.
Also try the "simulate memory warning" option in the simulator and see if that gets it to crash.