Lan Yi Education objective-c memory Management

Source: Internet
Author: User

First, memory management notes

1, OC Memory management, management stack memory, the primary management object is heap memory.
2, Memory count: There is pointing to it, its count is added one. Or that someone quoted it, counting plus one.

3. After no one is referenced, the memory count is 0. The object is destroyed. Memory is freed.
ARC compiler automatically add release automatic memory management The local variable is enclosed in parentheses, and automatically minus 1.
MRC Manual memory Management.
[A1 release] releases one, memory count minus one.

Two, all object reference count is 0 o'clock, to free memory, will be called: Method Dealloc.

Class to hit the plane, for memory management instances. explained that when the enemy aircraft were killed, should release memory. Check all the enemy objects have references to the location, when all the place is correctly released, then, hero killed enemy aircraft, will enter the Dealloc method, at this time you can output in the Dealloc method, if the correct memory management, memory is not disclosed, there will be "enemy aircraft dead" output.

The principle of arc is: who adds, who is responsible for reducing.
memory Count plus one case

1. The alloc command causes the memory count to be added one.
is: Who adds, who is responsible for reducing.

2.
eg
[[Self.view Addsubview:]] added to the interface memory count will increase with an indeterminate number.
[[Self.view Addsubview:]] +1
[E Removefromsuperview]; -1
3.
Add to Array
Subtract from array.
4.
Timer to ensure that the method call to the object succeeds
You also want to reference the object.

The keywords in the attribute brackets are used to control the contents of the set and get methods.

Retain (strong): Let the Set method do two things ① the original value of release that -1② the new pass in the value retain that is +1;
e.g.: Self.enemy why Self.enemy =[[Nsmutablearray alloc]init]; need to add a
Alloc +1
Self.enemy Set Method +1

Assign (weak) Let the set method do one thing
Assigning values passed in to a global variable is irrelevant to the memory count. Basic data types are used with assign. The default is assign.

Object type, why use strong. Strong keywords Why do you want to reduce the original value of one
eg.: If two times assignment
Occurrences 650) this.width=650; "src=" http://img.blog.csdn.net/20150905225038851 "alt=" Object type strong keyword action "title=" "style=" Border:none; "/>

650) this.width=650; "src=" http://img.blog.csdn.net/20150905225117036 "alt=" here write a picture describing "title=" "style=" border:none; "/ >

Self.enemy =[[Nsmutablearray alloc]init];+2

Self.enemy =[[Nsmutablearray alloc]init];

Release (Strong)
SELF.A = [[Uilable alloc]init];+2
Automatic memory Management 1. Use the same variable. If it is retain (strong), it will be reduced one more.
SELF.A = [[uilable alloc]init];

Example
One can only put one kite at a time.
The old kite must be taken back when the new kite is put up. Put the new.
If you don't take it back. Just put a new kite, then the old kite is like a decentralized walk let it go, to pollute the environment. *


This article is from the "Get" blog, so be sure to keep this source http://3517465.blog.51cto.com/3507465/1691659

Lan Yi Education objective-c memory Management

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.