@interface Teacher : NSObject {
        NSString *childhoodName;        // 8bytes
        short e;                       // 8bytes (short2字节,加6个占位字节)
        char f[8];                     // 8bytes 
        NSString *g;                 // 8bytes 
        int h;                       // 8bytes (int 4字节,加4个占位字节)
}
/** name */
@property (nonatomic, copy) NSString *name;   // 8bytes 
/** age */
@property (nonatomic, assign) int age;         // 8bytes (int 4字节,加4个占位字节)
/** other */
@property (nonatomic, copy) NSString *a;       // 8bytes 
@property (nonatomic, assign) int b;           // 8bytes (int 4字节,加4个占位字节)
@property (nonatomic, assign) char *c;     // 8bytes 
@property (nonatomic, assign) short d;     // 8bytes (short2字节,加6个占位字节)
@end
@implementation Teacher
@end
根据内存对齐原则可以得出上面这个类共占96bytes。(加上isa指针所占的8个字节)
但是通过下面的测试方法得出占80bytes:

Screen Shot 2018-04-16 at 15.07.05.png
可以看出苹果通过重排进行了优化。
现在手动对属性和成员变量『分别』重排进行优化后占72bytes,对应的 teacher 结构体如下:
struct teacher {
    char *isa;
    char *name;
    char *a;
    char *c;
    char *childhoodName;
    char *g;
    char f[8];
    int age;
    int b;
    int h;
    short d;
    short e;
};

Screen Shot 2018-04-16 at 15.13.01.png
72bytes与teacher类占80bytes不符,所以,苹果优化重排方式将变量类型按字节从大到小排列。而且是按照属性和成员变量『分别』重排进行优化,结构体如下:
struct teacher {
    char *isa;
    char *name;
    char *a;
    char *c;
    int age;
    int b;
    short d;
    
    char *childhoodName;
    char *g;
    char f[8];
    int h;
    short e;
};

Screen Shot 2018-04-16 at 15.17.47.png
参考文章:
runtime使用篇: class_getInstanceSize 和 苹果对内存的优化
更新-----2018.05.21
经反复测试,发现苹果当仅有成员变量,没有属性时,不会进行重排优化,原因暂时未知。测试结果如下:
#import <Foundation/Foundation.h>
#import <objc/runtime.h>
#include <stdio.h>
#include <malloc/malloc.h>
@interface Person : NSObject
@end
// Person.m
@interface Person ()
{
    NSString *qq;
    char ww;
    NSString *ee;
    char www;
    NSString *ggg;
    char d[7];
}
@end
@implementation Person
@end
int main(int argc, const char * argv[]) {
    @autoreleasepool {
        // insert code here...
        Person *per = [[Person alloc] init];
        long instanceSize = class_getInstanceSize([Person class]);
        long mallocSize = malloc_size((__bridge const void *)(per));
        
        NSLog(@"\nPersons的instanceSize:%ld \nPersons的mallocSize:%ld", instanceSize, mallocSize);
    }
    return 0;
}

Screen Shot 2018-05-22 at 00.08.27.png
如果Person经过重排的话:
struct Person 
{
    Class isa;  //8字节
    NSString *qq;
    NSString *ggg;
    NSString *ee;
    char d[7];
    char ww;
    char www;
};
重排后instanceSize的大小应该为:48才对。而打印结果为56,说明没有进行重排。
另外,Person的实例大小为56,当实际被分配的内存为64,这是因为系统为了提高寻址效率,(在Mac下),被分配的内存字节数均为16的整数倍