ios-3-Simple Memory Management

Source: Internet
Author: User

1. In OC, each object has a hold count, and each object has a retention count of 1 at the time of creation, and a retention count of 0 when released.

2. Create (auto-release) objects

+ (CAR *) car

{

Car *mycar = [[Car alloc] init];

return [MyCar autorelease];

}

3. Create a reserved property

@property (retain) Nsarray *colors;

After synthesize (synthesis) is created, the object is automatically persisted, and if the object is re-assigned, the preceding value is automatically freed

4. Other ways to create objects

General rules: By Alloc, new, create, copy of any method to build an object, you have to assume the responsibility to release the object , and the class method is different, the method with these words will not generally return the object automatically released

5. Releasing objects

Release properties: Self.year = nil;

Release variables: [age release];

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.