#在蓝懿学习iOS的日子 #day7

Source: Internet
Author: User

Today to learn the contents of memory management, more abstract, not a lot of applications, but still to understand, then I would like to review, learn the content bar!

One, ID: any object

Self: calling its own class

Super: Referencing properties of the parent class itself

Second, memory management

ARC: Automatic memory management

MRC: Manual Memory Management

1. Memory count mechanism: Memory count indicates the number of times the current object is referenced, and if the number of references is 0, the object will be freed from memory

Retain Memory Count +1

Release will count to memory-1

2. Effect of retain (strong) assign (weak) copy on the Set method:

Retain: Two things 1. Put the original release 2 new retain+1 —————— are now using strong

Assign: Direct assignment--------system default weak (can not write)

Copy: Call copy and assign a value

to add (a keyword) when declaring a property

Object

@property(nonatomic, strong) Nsmutablearray *myarray;

Basic data Types

@property(nonatomic)int x;

3. Dealloc method This method is called when the object memory count is 0, which is used in arc to verify that the object has not been released.

This method is called when the memory counter is 0 and is released until the object is freed .

Example:-(void) Dealloc

{

// need to put all global variables in release

//[_myarray release];

}

Iii. agreements (i.e. rules): only those who follow the agreement can perform some method

1. Create class in the. h file of the class

@protocol mandelegate <nsobject>

@optional// non-mandatory

@required// required

-(void) play;

@end

@interface man: nsobject

-(void) Playwithobject: (ID<mandelegate>) obj;

@end

2, in the class. M file

-(void) Playwithobject: (ID<mandelegate>) obj{

NSLog(@ "The big man is playing ");

[obj play];

}

3. Introduction of Class header files in viewcontroller.m

// Declaration Object

man * M =[[man alloc]init];

boy*b =[[boy alloc]init];

Girl *g =[[Girl alloc]init];

// How to use

[M playwithobject: b];

[M playwithobject: g];

Well, today summed up here, we encourage each other, come on!

#在蓝懿学习iOS的日子 #day7

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.