I'm creating a subclass of an existing class in runtime and adding there a couple of ivars. Then, I replace my original class with the class I've created in runtime:
Class RuntimeClass = objc_allocateClassPair(myObject.class, "RuntimeClass", 0);
class_addIvar(RuntimeClass, "_firstIvar", sizeof(NSString *), log2(sizeof(NSString *)), @encode(NSString *));
class_addIvar(RuntimeClass, "_secondIvar", sizeof(NSString *), log2(sizeof(NSString *)), @encode(NSString *));
object_setClass(myObject, RuntimeClass.class);
What I'm curious about is where is the memory taken for my ivars? My original class didn't have them but the exact amount of memory has already been allocated for the class.
Will these ivars steal this memory from some unexpected places and is it safer to use associated objects for this purpose?