Some details about MRC development

Source: Internet
Author: User

1. Who applies, who releases, applies to a principle of object-oriented development, "pairing principle"

2. If Alloc,retain,copy,new (alloc&init) is used when instantiating an object, a corresponding release method is required

-Allocwithzone does not need a paired release

3. Tools-Static analysis tools (analyze)

It is possible to analyze the existence of a memory defect from the code structure and not run the code itself, to discover most of the problems

4. If a method needs to return an object, the object to be returned needs to be added Autorelease, and the object will be destroyed before the auto-free pool is destroyed

To achieve the effect of delayed release!

5. If you are customizing a Copy object, you need to allocate space for the object using the Allocwithzone Method!

6. If the custom object has Copy,retain (equivalent to ARC's strong)

Need to be released in the Dealloc method

7. Knowledge Point Supplement:

When do you use _name? When do you use Self.name?

-self.name is an attribute that corresponds to a Getter&setter method

Use Self.name to ensure the balance of reference counting with the default setter method

-_name is a member variable and is an in-memory instance

Use details

* * In the first use, Apple recommends using _name to assign the initial value, for example: Loadview,viewdidload method

Tip: If you use lazy loading except

* * Use _name in the Dealloc method

In the MRC setter method

-(void) SetName: (NSString *) name {

1. Determine whether the assigned name and the original _NAME member variable are saved in the same context

if (name! = _name) {

Release old values

[_name release];

_name = name;

To make a strong reference to a new value

[_name retain];

}

}

8. If you are using a class method, or another object that returns an automatic release, you need to retain it yourself, or it will be released once you run the loop!

Some details about MRC development

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.