An error is caught, using Zombie
CFString Foundation Library
caller {NSPlaceholderMutableString int] Malloc
CFString Foundation Library
caller {NSPlaceholderString initWithFormat:locale} Zombie
well it didn't drop to where I declared. I have no idea where that NSMutablestring is called and which variable it is
Instruments provides an option to record reference counts -- ensure it's enabled.
Run your app and reproduce the issue.
When Instruments halts the program due to messaging a zombie, it will tell you the address of the zombie.
You then locate the address in the list of allocations and view the location it was created, as well as all its ref count ops.
It takes about 2 minutes to spot an issue once you get the hang of it, and can reproduce the problem. Good luck.
Also, 0x8badf00d has recommended "session 311 Advanced Memory analysis with Instruments." below. I've not watched it personally, but it sounds like it would be a great session on the subject.
Related
Recently my iphone project comes to the end, but suffer some random crash during app running, and the call stack is always located in COCOA library, tough issue, don't know how to deal with it, for some cases I even suspect that is it apple's defect?
My questions.
For those random crash issue with few reproduce rate, how do you guys handle it? Any method to help to increase reproducible rate?
How to fix these crashes located in COCOA library? How to find more clues?
Any idea or discussion will be appreciated, thanks in advance.
If the app crashes in the COCOA code it does not mean that COCOA code is wrong - much more likely you fed some invalid data to it (for example nil where it does not supposed to be). If it's happening randomly there might be some multithreading concurrency behind or some of your objects become (auto)released too early, etc. You have to carefully analyze your code which operates with the COCOA classes where your crash happens, or try memory management debugging as suggested by other answerers.
Generally, I don't start thinking that is COCOA the problem. It happens, but most cases the fault is ours.
When this kind of crashes happens the first thing to do is to run the static Analyzer, sometimes it's just a retain/release problem.
If you're using ARC, skip this part and start creating an Exception Breakpoint (search 'To add an exception breakpoint...' in linked guide). The exception breakpoint helps to have a more detailed crash log when an exception is thrown.
The third step is using Instruments, looking for waster memory, leaks and any other form of memory drain. How to use Instruments is deeply explained in a couple of WWDC videos.
Enable NSZombie flag.
project(On Top LeftCorner of xcode)>Diagnostics>enable zombie objects
It will lte u know where ur code is crashing ..find it fix it
I've been researching this throughout SO and some people said that this error is fine as long as the apps doesn't crash.
My app gets this error and after this when I try to tap on a row for a cell (calling didSelectRowAtIndexPath) it crashes. And it gives me an error UIImage sent message to deallocated message. I am guessing that this is because of the memory warning it has freed up some UIView's and therefore it crashes.
Why is this and how do I fix this? I've been debugging this for quite some time, using instruments, profiling, etc and had no luck.
I'd like to post some code, but don't know which one to post.
You have failed to retain something you cared about. From your message, I would suspect the object is a UIImage. Start by running the Static Analyzer and see if you're unretaining something obvious. Then inspect your ivars, particularly ones that are related to images. Make sure you access your ivars using accessors and not directly (except in init, the accessors themselves and dealloc). Make sure your object properties are defined with "retain".
You can use the "Zombies" instrument to help you track down which object is under-retained.
by one of your comments, it is very clear that the issue is with memory management and releasing your objects.... I suggest you to go a bit deep into your code and find out the code snippets where you are releasing you objects(or allocating them)... It can also be due to the fact that you are not at all releasing your objects after allocating and the processor trying to kill your app due to the lack of memory...And by the way, this kind of erros suck your time a lot... good luck...
I was testing for memory leaks by running the Leaks tool to analyze on the device. I saw a bunch of leaks like:
GeneralBlock-128 (or some other number), Responsible Library is Foundation, Responsible Frame is NSPlaceholderMutableString.
What do these mean and how to fix them?? I have A LOT of these!! Please help. Thanks.
NSPlaceholderMutableString is the class used in allocating new instances of NSMutableString. Check where you're creating these objects (charge the Foundation libraries to its callers in the data mining inspector) and you'll find where to audit your code. Beware that the Leaks tool is not 100% successful so there is some chance that you're seeing a false +ve, but it's still definitely worth checking out.
I have been debugging the infamous EXC_BAD_ACCESS error for a few days now. NSZombieEnabled = YES did not offer anything. The call stack was different everytime I received the error, which was once every 5 or 6 runs.
I saw a tip for enabling guard malloc (which is in the scheme editor now for Xcode 4) on Lou Franco's website: Understanding EXC_BAD_ACCESS. As soon as I did this, my program halted on the exact line that was causing this elusive error.
According to its description, guard malloc creates separate pages for every malloc and deletes the whole page when the memory is freed, thus crashing the program when the freed memory is accessed. For general development, why wouldn't I just keep guard malloc on all the time? It seems to catch certain types of memory errors easily. If I'm not testing memory management or performance specifically, is there some downside to using it?
Not only does it waste address space, but it will significantly slow down your program (potentially to the point where it's unusable, even on the simulator). I suppose for an iOS programme when you're running it on the simulator it's a bit moot (memory isn't a problem, and the performance hit isn't terrible either), but perhaps in the name of best practice you shouldn't run it constantly.
Allocating a whole 4K page for a couple bytes per malloc() wastes address space very quickly.
GuardMalloc does make an app run much slower, especially if you have a large number of allocations during the normal course of execution. I keep it turned off most of the time.
I turn GuardMalloc on to debug a crash that mangles the stack. Often, these have objc_msgSend at the top of whatever is left of the stack.
With GuardMalloc, the random effects of dangling pointers are prevented. The address in the pointer cannot be re-used and its memory location is made invalid. The crash will happen almost immediately, well before the stack is corrupted. This is great for C++ legacy code as well as new Objective-C.
I do leave the other memory debugging aids on full-time.
I'm having a table view of data. While scrolling my table 2 or 3 times so fast, its getting crashed. My gdb is telling like
"message sent to deallocated instance...."
Anyone know how to solve this?
yes, your reference counting has errors.
to find the object, enable NSZombies. enabling NSZombies will not free your objects -- but will generate runtime errors when you attempt to message an instance which would (under normal operation) have been deallocated. from there, you can learn more about the object (e.g. its type).
Instruments also has a NSZombie mode. it is very useful to point out an object/zombie's lifetime.
for more details, see:
http://www.cocoadev.com/index.pl?NSZombieEnabled
the link also details how you can configure your executable to run with zombies enabled. this is found in the section 'Use in Xcode'.