我正在使用 Ojb-c,我想知道一个对象的内存大小,但我得到了这个,
NSObject *obj = [[[NSObject alloc] init] autorelease];
NSLog(@"malloc size of myObject: %zd", malloc_size(obj));
NSLog(@"size of myObject: %zd", sizeof(obj));
malloc size of myObject: 16
size of myObject: 4
我知道sizeof(obj)是4,因为ios 32上的指针大小是4字节,有什么区别?
但不止于此,
@interface TestObj : NSObject
@property (nonatomic, retain) NSArray *arr;
@property (nonatomic, assign) int count;
@end
@implementation TestObj
@end
TestObj *obj2 = [[[TestObj alloc] init] autorelease];
NSLog(@"malloc size of obj2: %zd", malloc_size(obj2));
NSLog(@"size of obj2: %zd", sizeof(obj2));
malloc size of obj2: 16
size of obj2: 4
我怎么知道 TestObj 的实际大小?谢谢。