How to find the size of any object in iOS?

前端 未结 5 1864
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-23 12:45

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 *t         


        
5条回答
  •  清酒与你
    2020-12-23 13:16

    I would suggest using class_getInstanceSize and malloc_good_size to see what it'll round up to. This will not show the ivars and whatnot inside the returned size.

    #import 
    #import 
    
    NSLog(@"Object Size: %zd", malloc_good_size(class_getInstanceSize([yourObject class])));
    

提交回复
热议问题