As3 garbage collection: recycles loader objects in flashplayer10.1.

Source: Internet
Author: User
As3 and.. Net does not require developers to care about garbage collection. player releases memory for unreferenced objects at an uncertain time. Sometimes, the garbage collector must work as early as possible, to release a large amount of memory occupied Program It runs smoothly, so there is a method called hack on the network, as follows: Function GC (): Void {
Try {
New Localconnection (). Connect ( " Foo " );
New Localconnection (). Connect ( " Foo " );
} Catch (Error: Error ){
// Trace ("GC OK! ");
}
} However, this method does not work very well when the loader object is to be recycled (note that there is a word "too", which still works in the demo below ), then, find that the loader object in cs4 or later has the unloadandstop () method, so that when I remove the loader object from the stage, I will delete it as "clean ", and force garbage collection (call the above GC method ), Code As follows: Pictldr. addeventlistener (event. removed_from_stage, remove );
Function Remove (E: Event ): Void
{
Pictldr. removeeventlistener (event. removed_from_stage, remove );
Pictldr. unloadandstop ();
Pictldr. Unload ();
Pictldr = Null ;
GC ();
} In the demo below, a button is put, and click load and add a SWF file to the stage. A close button is in the upper right corner of the SWF file to remove itself from the stage, I keep clicking the two buttons back and forth. The test results show that the memory will not keep increasing and will remain fluctuating on a horizontal line. The figure shows the truth, that is, the memory usage shown in the task manager during the test:

 

Attach demo to download

Usage conditions of this demo:

1. I am using cs5, so please open it with cs5;

2. Flash player10.1 r52 is required for the player. I have used flash player10.0 for this test;

3. please go to beloaded. FLA puts more pictures or something. Let's put it around 10 MB. I uploaded only one picture (to reduce space and traffic, huh, huh). It's too small to see memory changes.

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.