Although I have been doing iOS development for some time, I have been busy with projects and have not carefully studied OC. It is rare that I have to study the OC information at leisure today and find that the effect is very good, however, I also felt that the technology update was too fast, and I found that the previous information was somewhat different from the current technology.
In terms of memory, the memory size of an object is determined by the member variables of this class when memory is allocated. For example:
@ Interface car: nsobject
{
Int year;
Nsstring * make;
Nsstring * model;
}
@ End
For this car class, the output result of the data is:
Nsobject * object = [[nsobject alloc] init];
Car * testcar = [[Car alloc] init];
Nslog (@ "% lu", sizeof (object); // 4B
Nslog (@ "% lu", sizeof (testcar); // 16b
The reason is that "the car class inherits nsobject, so there is 4B memory first, and each of the three member variables occupies 4B, that is, 4B + 3 * 4B = 16B ".
However, the output result is as follows:
Nslog (@ "% lu", sizeof (object); // 8b
Nslog (@ "% lu", sizeof (testcar); // 8b
All are 8B.
Object C memory allocation size