FLASH AS3 Image Memory Removal method

Source: Internet
Author: User

A recent project encountered loading external images caused high memory problems, through a variety of search finally solved, in fact, in the new version of Flash Player has a relevant method.

Project, a picture loaded into a file exists in the form of a bitmapdata class, even if remove or set to NULL is still useless.

Help can see that BitmapData has a method, Dispose, as follows:


Dispose () method
Public function Dispose (): void
Language version: ActionScript 3.0
Runtime version: Flash Player 9, AIR 1.0, Flash Lite 4
Frees the memory used to store the BitmapData object.

When you call the Dispose () method on an image, the width and height of the image is set to 0. All subsequent calls to the method or property of this BitmapData instance will fail and throw an exception.

Bitmapdata.dispose () Immediately releases the memory occupied by the actual bitmap data (a bitmap can use up to a maximum of MB of memory). With Bitmapdata.dispose (), the BitmapData object is no longer available, and if a function is called on the BitmapData object, the Flash runtime throws an exception. However, Bitmapdata.dispose () does not use the BitmapData object (approximately 128 bytes) as garbage collection, and the memory that is consumed by the actual BitmapData object is released when the BitmapData object is collected by the garbage collector.

Combined with the System class GC method, the memory is completely freed, at least the problem in my project has been solved.

GC () method
public static function GC (): void
Language version: ActionScript 3.0
Runtime version: AIR 1.0, Flash Player 9.0.115.0, Flash Lite 4
Forces the garbage collection process to take.

limited to Flash Player Debug version and AIR application only. in an air application, the System.GC () method is enabled only in content that is running in air Debug Launcher (ADL) or in the application security sandbox of an installed application.

However, it is important to note that the picture is not used after the call, otherwise it will not be displayed directly.

FLASH AS3 Image Memory Removal method

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.