Instantiating objects and managing memory
There is no Automatic Reference Counting (ARC) in Cocos2d-x, so Objective-C developers who have forgotten memory management might have a problem here. However, the rule regarding memory management is very simple with C++: if you use new
, you must delete. C++11 makes this even easier by introducing special pointers that are memory-managed (these are std::unique_ptr
and std::shared_ptr
).
Cocos2d-x, however, will add a few other options and commands to help with memory management, similar to the ones we have in Objective-C (without ARC). This is because Cocos2d-x, unlike C++ and very much like Objective-C, has a root class. The framework is more than just a C++ port of Cocos2d. It also ports certain notions of Objective-C to C++ in order to recreate its memory-management system.
Cocos2d-x has a Ref
class that is the root of every major object in the framework. It allows the framework to have autorelease
pools and retain
counts, as well other Objective...