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 ):
- Weak References
- Self References
- 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.