Enable Malloc Scribble(开启Malloc Scribble(内存涂鸦)):Malloc Scribble的基本思想是,在对象被释放后,在对应内存块中填上不可访问的无意义的数据(0x55),那么我们再使用这个对象时,程序将直接Crash。参考:http://weibo.com/p/10080852e0242ca7393837a6ecec8009daad5a?k=iOS知识小集&from=501&_from_=huati_topic
Memory Management options:
-
Enable Scribble. Fill allocated memory with
0xAA
and deallocated memory with0x55
. -
Enable Guard Edges. Add guard pages before and after large allocations.
-
Enable Guard Malloc. Use
libgmalloc
to catch common memory problems such as buffer overruns and use-after-free. -
Enable Zombie Objects. Replace deallocated objects with a “zombie” object that traps any attempt to use it. When you send a message to a zombie object, the runtime logs an error and crashes. You can look at the backtrace to see the chain of calls that triggered the zombie detector.
Logging options:
-
Distributed Objects. Enable logging for distributed objects (
NSConnection
,NSInvocation
,NSDistantObject
, andNSConcretePortCoder
). -
Garbage Collection Activity. Enable various logging facilities in the garbage-collected memory allocator. Log when a collection occurs, log when new regions are allocated, and log all weak reference manipulations.
-
Malloc Stack. Record stack logs for memory allocations and deallocations.
-
Log Exceptions. Log Objective-C runtime exception handling.
-
Log DYLD API Usage. Log dynamic-linker API calls (for example,
dlopen
). -
Log Library Loads. Log dynamic-linker library loads.
Debugger options:
-
Stop on Debugger() and DebugStr(). Enable Core Services routines that enter the debugger with a message. These routines send a SIGINT signal to the current process.
The Xcode static analyzer parses the project source code and identifies these types of problems:
-
Logic flaws, such as accessing uninitialized variables and dereferencing null pointers
-
Memory management flaws, such as leaking allocated memory
-
Dead store (unused variable) flaws
-
API-usage flaws that result from not following the policies required by the frameworks and libraries the project is using