places in Flex that could lead to memory leaks
There are a number of situations that can cause memory leaks: event snooping:
A listener function is added to the parent object, which causes a memory leak, for example:
Override protected function Mousedownhandler (...): void
{
systemmanager.addeventlistener ("MouseUp", Mouseuphandler);
......
Solve:
Remove these listeners while destroying the object, although weak references can also avoid these problems, but it feels better to be in control.
However, the following scenarios do not cause memory leaks: Weak references: Someobject.addeventlistener (Mouseclick.click, handlerfunction, False, 0, true); References to yourself: This.addeventlistener (Mouseclick.click, handlerfunction); References to child objects:
private var childobject:uicomponent = new UIComponent;
AddChild (childobject);
Childobject.addeventlistener (Mouseevent.click, ClickHandler);
Anyway... There are AddEventListener, just removeeventlistener a bit, to do for their own things ~ haha Clear Reference
Removing the child object does not delete the object, and he remains in memory, and the reference should be set to NULL
Removechildren (obj);
obj = null;
Static Members
In Class (or mxml), there are:
public static Var _eventservice:myservice=new myservice ();
Workaround: When you dispose, you need to set:
_eventservice =null;
module (not resolved)
After Moduleloader UnloadModule
Moduleinfo will not be GC.
Garbage Collection in a multicore Modular Pipes application
This article describes a GC policy that feels invalid for Moduleinfo GC.
(not tried, not encountered) CSS Styles
If a shell's CSS definition or such definition is used in the module, then the module will not be GC.
The popup window should be the same result.
Workaround, use the dynamic CSS file
in module Init
Stylemanager.loadstyledeclarations ("css/mystyle.swf");
Module in Dispose
Stylemanager.unloadstyledeclarations ("css/mystyle.swf");
Textinput/textarea (not resolved)
If the module has windows using the Textinput/textarea control, no click No problem, as long as the point up, then unfortunately, module and the form will not be GC.
This bug is very serious and there is no workaround at this time.
Memory leak when using TextInput and TextArea when click the keyboard the appended workaround is invalid.
Through profiler analysis, should be related to Focusmanager, only one click will not be released. Cursormanager.setcursor
Used a
Cursorid = Cursormanager.setcursor (iconclosed);
Dispose when you want to
Bitmap
If you use bitmap, you need to call its Dispose method at the end, otherwise the memory consumption is huge.
In addition, BitmapData can be shared, and multiple bitmap can use the same bitmapdata, saving a lot of memory.
var bmp:bitmap =new Bitmap ();
........
if (bmp.bitmapdata!=null) {
bmp.bitmapData.dispose ();
}
Image
When an image object is included, it is not released when Removechildren (test multiple times, the results are different, it is recommended to do the following).
Solve:
Img.source = null;
This.removechild (IMG);
img = NULL;
Loader, SWFLoader, sound, video, effect, etc. ..If the SWF file is loaded, stop playback first. Stop sound playback Stop the movie clip that is playing (Movieclip) closes any connected network objects, such as loader being loaded, to first close. Canceling a reference to a camera or microphone canceling an event listener stops any running timer, clearinterval () stops any timer object, Timer.stop () stops the effect being played (Effect)
other
The binding is also suspected to have memory leak problem.
References and memory leaks related posts and materials:
Http://blogs.adobe.com/aharui/2007/03/garbage_collection_and_memory.html
http://www.craftymind.com/2008/04/09/kick-starting-the-garbage-collector-in-actionscript-3-with-air/
Http://www.cnblogs.com/janyou/archive/2008/11/25/1340753.html
http://www.dreamingwell.com/articles/archives/2008/05/understanding_m.php
Summary: Because before Flash has been used on the Web page, the General page is closed after reading, estimated that adobe in the memory recycling this piece is not too much effort, now the advent of air makes memory management is also very important, and air itself on the memory consumption is quite large, An air program that is initially created without any content will have to take up 10-20m+ of memory ... Air also needs to be improved.