Cocos2d-x (3.0 +) memory management framework and mechanism

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.