Labels: cocos2d-x memory management framework
The Cocos2d-x uses a reference counting method to manage memory objects through class ref, autoreleasepool, and poolmanager.
Ref is the reference Count class, and its constructor is the protected access type. When a ref object is created, its reference count is 1.
When an object is created, create is called, and autorelease is called to put the object into the object pool (an object in the autoreleasepool) for unified management,
Retain increases the reference count, and the reference count will be reduced immediately when release is called.
After the engine is initialized, a default automatic release Object List autoreleasepool is created and added to the poolmanager for management.
In each primary loop, a pool is cleared and all objects with zero counts are deleted. This is the memory management method in cocos2dx.
Poolmanager is in singleton mode and is maintained by the engine automatically without the need for coders.
It contains the main member variables and member functions of the three classes. The last column summarizes the white member functions, while the orange member variables. Cocos engine Cocos coders have extremely standardized names, see the meaning of the word, worship! You can refer to this figure to see the source code.