------<a href= "http://www.itheima.com" target= "blank" >java training, Android training, iOS training,. NET training </a>, look forward to communicating with you! -------
1. Storage details of objects
class to create objects, each object in memory occupies a certain amount of storage space, each object has a separate member variable, all the object common class member method, method in the whole memory only one copy, the class itself in memory occupies a storage space, the method of class exists here.
Example:
#import <Foundation/Foundation.h>
Person.h file
@interface Person:nsobject
{
int _age;
NSString *_name;
}
-(void) run;
@end
PERSON.M file
@implementation person
-(void) run{
NSLog (@ "people running");
}
@end
int main (int argc, const char * argv[]) {
@autoreleasepool {
Person *pe = [person new];
Pe.name = @ "Xue-li";
Pe.age = 18;
NSLog (@ "Name:%@, Age:%d", pe.name,pe.age);
[PE run];
[Person new]; three things to do
1. Apply for memory space
2. Initialize the instantiated variable.
3. Return to the first address of the space
Question 1: Which area of the memory is applied for space?
New when applying space in the heap area of memory (the program dynamically allocates memory space)
Initialized to 0 if the instance variable is the base data type at the time of initialization
If the OC string type is initialized to null
2: Instance variables are saved in the declaration place?
Heap pointer variables are stored in the stack area
Question 3: Where is the object method saved?
Code Area
}
return 0;
}
Dark Horse Programmer---iOS learning log 12