1.alloc
源码
+ (id)alloc {
return _objc_rootAlloc(self);
}
id _objc_rootAlloc(Class cls)
{
return callAlloc(cls, false/*checkNil*/, true/*allocWithZone*/);
}
2. init
init源码
- (id)init {
return _objc_rootInit(self);
}
id _objc_rootInit(id obj)
{
// In practice, it will be hard to rely on this function.
// Many classes do not properly chain -init calls.
return obj;
}
结论
通过init源码可以看出,init直接返回来了alloc的对象
3. new
new源码
+ (id)new {
return [callAlloc(self, false/*checkNil*/) init];
}
结论
alloc通过调用_objc_rootAlloc, _objc_rootAlloc调用callAlloc,new 直接调用callAlloc 并init所以 new相当于调用alloc init
4. 比较
new出的对象无法调用各种initWith...方法;