Guard Malloc instantly detected an EXC_BAD_ACCESS error. Why not use all the time?

I debugged the shameful error EXC_BAD_ACCESS for several days. NSZombieEnabled = YES did not offer anything. The call stack was different every time I received an error that was every 5 or 6 starts.

I saw a hint to enable malloc protection (which is now in the schematic editor for Xcode 4) on the Lou Franco website: Understanding EXC_BAD_ACCESS . As soon as I did this, my program settled on the exact line that caused this elusive error.

According to its description, guard malloc creates separate pages for each malloc and deletes the entire page when freeing memory, which leads to a program crash when accessing free memory. For general development, why don't I just keep the malloc guard all the time? It seems easy to catch certain types of memory errors. If I do not test memory management or performance specifically, is there a drawback to using it?

+6
malloc iphone exc-bad-access guard
source share
3 answers

Not only is this the address space for waste, but it will also significantly slow down your program (possibly to the extent that it is not used, even on a simulator). I believe that for an iOS program, when you run it on a simulator, it is a bit controversial (memory is not a problem, and a performance hit is not a big deal either), but perhaps in the name of best practice you should not constantly run it.

+7
source share

Allocating an entire 4K page for a couple of bytes on malloc() very quickly deletes the address space.

+3
source share

GuardMalloc makes the application much slower, especially if you have a large number of allocations during the normal course of execution. I keep it off most of the time.

I enable GuardMalloc to debug the failure that controls the stack. Often they have objc_msgSend at the top of what remains of the stack.

With GuardMalloc, the random effects of dangling pointers are prevented. The address in the pointer cannot be reused, and its memory location is not valid. A crash will occur almost immediately, long before the stack is damaged. This is great for old C ++ code, as well as for the new Objective-C.

I leave the tools for debugging memory full time.

+2
source share

All Articles