Class data structure

  • Memory structure without member variables

  • Memory analysis diagram

  • A memory structure with member variables

  • Memory view

  • View memory data in real time

  • LLDB – instruction

  • LLDB practice

How much memory is required to create an instance object? #import

class_getInstanceSize([NSObject class]);

How much memory is actually allocated for creating an instance object? #import

malloc_size((__bridge const void *)obj);

#import <Foundation/Foundation.h> #import <objc/runtime.h> #import <malloc/malloc.h> // NSObject Implementation struct NSObject_IMPL { Class isa; // 8 bytes}; // typedef struct objc_class *Class; int main(int argc, const char * argv[]) { @autoreleasepool { NSObject *obj = [[NSObject alloc] init]; NSLog(@"%zd", class_getInstanceSize([NSObject])); NSLog(@"%zd", class_getInstanceSize([NSObject])); NSLog(@"%zd", malloc_size((__bridge const void *)obj)); // Windows, MAC, iOS // emulator (i386), 32bit(armv7), 64bit (arm64)} return 0; }Copy the code

OC source code download address

  • If it’s less than 16, it’s going to be 16

Oc Object classification

  • Objects in Objective-C, OC objects for short, fall into three main categories
    • Instance Object Instance object
    • Class object Class object
    • Meta-class metaclass object

instance

class

meta-class

Pay attention to

Check whether the Class is meta-class