f. e. (just for understanding messages mechanism more clear) I have class
MyClass.h
@interface MyClass : NSObject {
int ivar1;
int ivar2;
}
+ (id)instance;
@end
MyClass.m
static MyClass* volatile _sInstance = nil;
@implementation MyClass
+ (id)instance {
if (!_sInstance) {
@synchronized(self) {
if (!_sInstance) {
_sInstance = [[super allocWithZone:nil] init];
}
}
}
return _sInstance;
}
@end
What will be send in objc_msgSend in fact when calling [super allocWithZone:nil]
?
objc_msgSend([MyClass class], "allocWithZone", nil)
or objc_msgSend([NSObject class], "allocWithZone", nil)
?
In practice I think that called objc_msgSend(self, "allocWithZone", nil)
and in that case self == [MyClass class];
I want to be sure that memory for ivar1 and ivar2 will be allocated.
Is it true, that when we call super in class method, in objc_msgSend() function the "self" argument is passed, that in our case is class object of child? And allocWithZone will "look" at the child class object to see how much memory should be allocated for ivar1 and ivar2.
Thanks!