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