Flex/AS 3 memory leak

Source: Internet
Author: User

According to the current situation, Flex 3 (AS3) has a serious memoy leak (Memory leakage) problem. Some of these problems can be avoided by appropriate encoding methods, there are still some problems that are only waiting for the Flex SDK to be updated.

I feel that Flex's commercial application is only available in its infancy.

List some scenarios that generate memoy leak.

(1) Event Listeners

Listening to parent objects does cause memory leaks

E.g.

Override protected function mouseDownHandler (...) : Void {
SystemManager. addEventListener ("mouseUp", mouseUpHandler );

You can:

1. Removing the addEventListener (when dispose ).

SystemManager. removeEventListener ("mouseUp", mouseUpHandler );

2. Use of weak reference listeners

Override protected function mouseDownHandler (...) : Void {
SystemManager. addEventListener ("mouseUp", mouseUpHandler, false, 0, true );

These do not block garbage collection (generally do not cause memory leaks ):

    1. Weak References
    2. Self References
    3. References to Child Objects

Weak reference event listener e.g.

SomeObject. addEventListener (MouseClick. CLICK, handlerFunction, false, 0, true );

Self References e.g.

This. addEventListener (MouseClick. CLICK, handlerFunction );

ChildObject event listener e.g.

Private var childObject: UIComponent = new UIComponent;
AddChild (childObject );
ChildObject. addEventListener (MouseEvent. CLICK, clickHandler );

We recommend that you removeEventListener all addEventListener, or use Weak References.

 

Reference:

Http://blogs.adobe.com/aharui/2007/03/garbage_collection_and_memory.html

Http://www.dreamingwell.com/articles/archives/2008/05/understanding_m.php

(2) StaticMembers

E.g.

Class (or MXML) contains:

Public static var _ eventService: MyService = new MyService ();

When dispose, you need to set:

_ EventService = null;

(3) module (unsolved)

After moduleLoader unloadModule

ModuleInfo is not GC.

Garbage Collection in a MultiCore Modular Pipes Application

This article introduces a GC strategy, which is ineffective for the GC of ModuleInfo.

 

(4) CSS Style

If the shell CSS definition or <mx: Style> definition is used in the module, the module cannot be GC.

The pop-up window should be the same result.

Solution: Use Dynamic CSS files

Module init

StyleManager. loadStyleDeclarations ("css/myStyle.swf ");

Module dispose

StyleManager. unloadStyleDeclarations ("css/myStyle.swf ");

 

(5) TextInput/Textarea (unsolved)

If the TextInput/Textarea control is used in the window in the module and there is no problem if you do not click it. As long as you click it, it is a pity that the module and the form cannot be GC.

This BUG is very serious and there is no solution yet.

Memory leak when using TextInput and TextArea when click the keyboard. the attached solution is invalid.

Through profiler analysis, it should be related to the Focusmanager, and will not be released with only one click.

 

(6) CursorManager. setCursor

Used

CursorID = CursorManager. setCursor (iconClosed );

For dispose

CursorManager. removeCursor (cursorID );

 

(7) Bitmap

If you use Bitmap, you need to call its dispose method at the end, otherwise the memory consumption is huge.

Var bmp: Bitmap = new Bitmap ();

........

If (bmp. bitmapData! = Null ){
Bmp. bitmapData. dispose ();
}

 

(8) Others

Binding is also suspected to have memor leak problems.

......

I feel that Flex/AS 3 is still a long way to go from commercial development.

Related Article

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.