After having experienced serious memory leak problems in some applications and
after a lot of testing and reading about garbage collecting issues in AS3 (see interesting links about GC issues at the bottom of this page), I learned
that one of the biggest cause are listeners not removed: above all listeners
created with strong references.
So I decided to write a simple application that scans one or more directories
for actionscript files and checks their content to see whether or not every
addEventListener has a corresponding removeEventListener set.
The application creates a log file containing detailed results about unmatched
pairs.
Beyond checking in broad terms his own code, a programmer can use this program
to get a sense of the code written by third parties in the case you have to
load their assets or their modules in your main application (being stated you
have access to the source code of these third parties).
It's my first application in Adobe Air: surely it could have been written better.
Maybe next time :D
After having istalled the application, all you have to do is to select the root
folder where your .as files are located and to select a folder for ouput logs.
Then press the button Start and wait for the process to complete (pic. 1).
The application creates a log file in the directory you have specified then
displays it (pic. 2).
Finally you can consult the log file in order to check potential problematic
situations.
Please note that the application only read your files .as but does not modify
them in any case!
clip.removeEventListener(MouseEvent.CLICK,handler); .. clip.addEventListener(MouseEvent.CLICK,handler);In this case the application matches the listeners and no warning is reported.
clip.addEventListener(MouseEvent.CLICK,addAsync(handler,100),false,0,true);In this case the listener will be marked as a strong reference also if it is not.
clip.addEventListener(MouseEvent.CLICK, handler);In this case the listener will result incomplete but no warning is reported.
clip.addEventListener(MouseEvent.CLICK,handler); .. .. var p_mc:MovieClip = clip; p_mc.removeEventListener(MouseEvent.CLICK,handler);Example 2:
clip.addEventListener(MouseEvent.CLICK,handler); .. clip.removeEventListener("click",handler);and so on...
gskinner.com: gBlog - Failure to Unload: Flash Player 9's Dirty Secret
Kirupa.com Forum - Garbage Collection: Reference Counting & Mark and Sweep
BIT-101 Blog - AS3 Garbage Collector Note
White Noise Blog - Garbage Collection in Flash AS3
THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
You can contact me by sending suggestions, complaints or whatever at:
iltimido@genereavventura.com
©2008 IlTimido - genereAvventura - Distribute under Creative Commons License