Considering this:
NSArray *foo; NSLog(@"%d", sizeof(foo));
You will get either 4 or 8, depending on whether you are using a 32 or 64-bit system. Note that I intentionally did not initialize foo ; there is no need to do this, since sizeof(foo) gives the byte foo , and foo is just a random pointer to an object. It would not matter if it was id foo; void*foo; NSString*foo; id foo; void*foo; NSString*foo; everything would be 4 or 8.
If you want the allocated size of an instance of a particular class, the Objective-C runtime provides an introspection API that can do just that. However, I cannot think of any reason why this would be more than curious in the program.
Note that the instance allocation size does not account for any sub-distributions. That is, NSArray probably has backup storage, which is a separate distribution.
Repeat:
sizeof (foo) in the above code has nothing to do with the size of the selected instance.
bbum
source share