If you look at the code of the CCObject class, you will see that the number of references to the constructor is set to 1. Thus, creating an object using new
is correct. Init is not called because the CCObject class does not have such a method. I usually prefer to create objects using a static constructor. Smth like
MyClass* MyClass::createInstance() { MyClass* object = new MyClass(); // you can create virtual init method // and call it here if( initWasSuccessful ) { object->autorelease(); } else { CC_SAFE_RELEASE_NULL(object); } return object; }
About all macros like CC_SAFE_DELETE - you can find them in the code cocos2dx. These macros simply check if the object is NULL to prevent a crash when trying to call the release method.
source share