Use instrument to solve zombie problems

Source: Internet
Author: User

The so-called zombie problem is that the application crashes because the programmer references the "zombie object" in the code. The so-called zombie object is a deallocated object. The retaincount of these objects is already 0. through normal means, we cannot track and observe them in debug.

If zombie enabled is enabled, the console outputs the address of the zombie object when a zombie problem occurs, and the program will generate a breakpoint here:

* **-[Calayer retaincount]: Message sent to deallocated instance <memoryaddress>

Although you can see that the memory address is a pointer that causes zombie reference, it is useless to solve the problem because you don't know which object the address is? Obviously, since this object is a deallocated object, you can no longer retrieve it from the memory and it "disappears. You can print the pointer as an object:

(GDB) PO <memory address>

You will still get an error message from message sent to deallocated instance.

Fortunately, these zombie objects can be observed using the zombie template of instrument.

Tip: You can only use the zombie template in the simulator. For programs running on the device, you can only manually find the zombie object. The zombie template is invalid for the physical device.

Click project> profile in xcode. In the Template Selection window of instrument, select the zombie Template under iossimulator.

Debug the program in the simulator. If the zombie problem occurs, the program will crash, and the instrument will pop up a "zombie message Report", and the program will be interrupted here, as shown in.

Click the arrow on the right of the address (0x158b3c00) to list the retain/release actions that have occurred to the zombie object.

Find the row whose retain count is before-1 in the list, Open View-> extended detail, and the code call that leads to the transition release will be displayed:

Double-click the code to highlight the statement in the source file:

Now, do you know where the problem is?

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.