Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How much memory is reserved when initializing NSObject?

Tags:

objective-c

When I use this statement in objective c

NSObject object = [[NSObject alloc] init];

How much memory is reserved for object?

like image 594
orak Avatar asked Feb 19 '23 07:02

orak


1 Answers

You can test the size of objects with the following code:

#import <malloc/malloc.h>
//...
NSObject *obj = [[NSObject alloc] init];
NSLog(@"Size: %zd bytes", malloc_size((__bridge const void *)(obj)));

This test produced: "Size: 16 bytes"

like image 151
J Shapiro Avatar answered Mar 03 '23 00:03

J Shapiro