ios--Detect Wild Hands

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.