As3 performance: Object pool technology

Source: Internet
Author: User

Why use an object pool?

Because Flash is a managed GC to clean up resources, and only GC knows when to clean up the resources, then our game's performance will be .........

For example, if you click a button in a game, an image is loaded and you click the image again to destroy the image.

If the user does not stop clicking, the user will continuously load and display the destruction. Memory is difficult to control.

 

From Adobe

Http://help.adobe.com/zh_CN/as3/mobile/WS948100b6829bd5a6-19cd3c2412513c24bce-8000.html

Use the object pool whenever possible.

Another important optimization is called the object pool, which involves repeated use of objects. Before initializing an applicationProgramDuring this period, a certain number of objects are created and stored in a pool,

For example, an array or vector object. After an object is operated, stop the object to avoid it occupying CPU resources, and then delete all references to each other. However,

Do not set referenceNull,This will make it meet the garbage collection conditions. You only need to put this object back in the pool and search for it when you need a new object.

Reusing objects can reduce the need for instantiating objects, and the cost of instantiating objects is high. It can also reduce the chances of running the Garbage Collector, thus improving the speed of application running.

After the object pool is used

We will first create the desired instance and throw it into the objectpool of the Object pool.

    • The object pool should be obtained by a singleton.
    • Start time: a certain amount of objects are directly assigned to the pool during initialization.
    • Use Time: Borrow from objectpool
    • Upon destruction (release): return it to objectpool
    • Completely released: the pool vector always references the sprite object. To completely delete objects from the memory, use the spritepool classDispose ()To delete all the remaining references.

 

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.