Getting Started with iOS development: Performance Optimization – Solution to memory leak issues

Source: Internet
Author: User

Solution to memory leak problem

A memory leak (Memory leaks) is when an object or variable is not released after use, and the object holds the memory until the application stops. If this object is too much memory will be exhausted, other applications will not run. This problem is more common in the MRR of C + +, C and objective-c.

The memory that frees objects in Objective-c is to send release and autorelease messages, both of which can subtract the reference count by 1, and when the reference count is 0, releasing message causes the object to be released immediately. The autorelease message causes the object to be put into a memory-free pool for deferred release.

Code on:

-(void) viewdidload {[Super viewdidload]; 
     
NSBundle *bundle = [NSBundle mainbundle]; 
     
NSString *plistpath = [Bundle pathforresource:@ "Team" oftype:@ "plist"]; 
     
Gets all the data in the attribute list file Self.listteams = [[Nsarray alloc] initwithcontentsoffile:plistpath]; 
     
}-(UITableViewCell *) TableView: (UITableView *) TableView Cellforrowatindexpath: (Nsindexpath *) IndexPath { 
     
static NSString *cellidentifier = @ "Cellidentifier"; 
     
UITableViewCell *cell = [TableView dequeuereusablecellwithidentifier:cellidentifier]; if (cell = = nil) {cell = [[UITableViewCell alloc] Initwithstyle:uitableviewcellstyledefault reuseidentifier:cellid 
     
Entifier]; 
     
Nsuinteger row = [Indexpath row]; 
     
Nsdictionary *rowdict = [Self.listteams objectatindex:row]; 
     
Cell.textLabel.text = [rowdict objectforkey:@ "name"]; 
     
NSString *imagepath = [rowdict objectforkey:@ "image"]; ImagePath = [ImagePath Stringbyappendingstring:@ ". png"]; 
     
Cell.imageView.image = [UIImage Imagenamed:imagepath]; 
     
Cell.accessorytype = Uitableviewcellaccessorydisclosureindicator; 
     
return cell; }-(void) TableView: (UITableView *) TableView Didselectrowatindexpath: (Nsindexpath *) Indexpath {Nsuin 
     
Teger 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 show]; 
     
[TableView Deselectrowatindexpath:indexpath Animated:yes]; }

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.