Getting Started with iOS development: Performance tuning – Finding and resolving zombie objects

Source: Internet
Author: User

A memory leak is when an object or variable is not released after use, so what if we go another extreme? This causes the transition release problem to cause the object to "zombie", which is called a Zombie (Zombies) object. An object has been freed, or the caller does not have ownership of the object and releases it, causing the transition to be released, creating zombie objects.

Zombie objects may sound very scary to many people, also very unfamiliar, if you want to talk about exec_bad_access abnormalities, may be not unfamiliar to everyone. An attempt to invoke the Zombie object method application crashes (the application jumps directly) and throws an exception exec_bad_access.

Let's take a look at the code snippet Viewcontroller:

-(void) TableView: (UITableView *) TableView Didselectrowatindexpath: (Nsindexpath *) Indexpath {Nsuinteg 
     
Er row = [indexpath row]; 
     
Nsdictionary *rowdict = [Self.listteams objectatindex:row]; 
     
NSString *rowvalue = [rowdict objectforkey:@ "name"]; NSString *message = [[NSString alloc] initwithformat:@ "You chose the%@ team. 
     
", Rowvalue]; Uialertview *alert = [[Uialertview alloc]initwithtitle:@ "Please select Team" Message:message delegate:self 
     
    uttontitle:@ "OK" otherbuttontitles:nil];                                                                                                                                          [Alert release]; 
     
    ①[message release];                                                                                                                                             [Alert show]; 
     
②[tableview Deselectrowatindexpath:indexpath Animated:yes]; }

Look at the bold part of the code, and you'll see what the problem is? The result of the program running throws a Exec_bad_access exception. Assuming we can't find the problem now, we can use the instruments tool's zombies trace template. Where instruments Select the Zombies template, click the Profile button to enter.

Related Article

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.