Search code examples
iphoneobjective-ccocoa-touchios4

How to find the size of any object in iOS?


I was optimizing my app and wanted to know that how much is the size of the object, so that I can also show it in log.

suppose I have

NSDictionary *temp=(NSDictionary*)[Data objectAtIndex:i];

//data is defined in the .h file 

now how will I know that how much is the size of the object temp?

I tried using the variable view and in the temp section I found:

instance_size=(long int)30498656

Is the instance_size the exact size of my temp object?.

I also tried

sizeof(temp);

but it crashed on that point. Any help...?


Solution

  • The compiler knows only about the pointer, and that is why it will always return size of the pointer. To find the size of the allocated object try something like

    NSLog(@"size of Object: %zd", malloc_size(myObject));