Targeting wild pointers You can also use zombie objects in addition to malloc Scribble (Memory doodle). The so-called Zombie object is to mark the freed object as a zombie, the system will not reclaim the memory of these objects, and so that the memory can not be reused, and therefore will not be overwritten.
When Zombie object is enabled, during debugging, if the object is freed, it is converted to zombie object. If you send a message to the object again, the corresponding zombie object receives the message and throws an exception. The object that is freed is clearly described in the exception information, and which message is received.
To turn on the zombie object, you can check "Edit scheme", "Diagnotics", "Enable Zombie Objects", shown in 1.
Let's look at a simple example to compare the behavior of the program before and after the zombie object is turned on. The code looks like this, and we declare the array as a __unsafe_unretained pointer, which is immediately released after the assignment and will not be set to nil.
__unsafe_unretained Nsmutablearray *arraym = [[Nsmutablearray alloc] init]; [Arraym AddObject: @" 1 " ]; [Arraym AddObject: @" 2 " ]; NSLog (@ "=%@", Arraym);
When the Zombie object is not turned on, the program runs correctly and prints the array. If the Zombie object is turned on, the program crashes, as shown in exception message 2.
ios--Detect Wild Hands