Build Your own recycling pool

Source: Internet
Author: User

http://blog.csdn.net/haomengzhu/article/details/27693365

The engine maintains a recycling pool, and all Autorelease objects are added to the pool.

Multiple auto-recycle pools are arranged into a stack structure, and when we manually create the recycle pool, the recycle pool is pushed to the top of the stack, and the Autorelease object is added only to the top pool. When the recovery pool of the when top layer is ejected, all objects inside it are freed once, and then the Autorelease objects that appear are added to the next pool.

Cocos2d-x has ensured that the Recycle pool is released once each frame ends and a new recycle pool is created before the next frame starts, but we should also

Considering that the recycle pool itself maintains a list of objects that will perform the release operation, if a large number of Autorelease objects are generated within a frame, the performance of the Recycle pool will degrade.

Therefore, before and after generating Autorelease object-dense areas (usually loops), it is better to manually create and release a recycling pool.

Step A
Obj1->autorelease ();
Obj2->autorelease ();

Step b
Poolmanager::getinstance ()->push (this);

Step c
for (int i=0; i<n; i++) {
Obj_array[i]->autorelease ();
}
Step d
Poolmanager::getinstance ()->pop ();
Step E
Obj3->autorelease ();

Build Your own recycling pool

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: info-contact@alibabacloud.com 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.