#import <malloc/malloc.h>
#import <objc/runtime.h>
NSObject *a = [[NSObject alloc] init];
NSLog(@"%lu %lu %lu",malloc_size((__bridge const void *)(a)),class_getInstanceSize([NSObject class]),sizeof(a));
![](https://img.haomeiwen.com/i6421068/e982cf4ec794cc1b.png)
结论 系统会分配16个字节 真正利用的只有8个字节
#import <malloc/malloc.h>
#import <objc/runtime.h>
NSObject *a = [[NSObject alloc] init];
NSLog(@"%lu %lu %lu",malloc_size((__bridge const void *)(a)),class_getInstanceSize([NSObject class]),sizeof(a));
结论 系统会分配16个字节 真正利用的只有8个字节
本文标题:NSObject分配多少字节及其本质相关
本文链接:https://www.haomeiwen.com/subject/fnsbohtx.html
网友评论