AS3 Garbage Collection with Event Listeners

A quick word of warning to AS3 programmers. Don’t use anonymous functions with event listeners, because they WILL be garbage collected.

Took me forever to find this bug, it seemed that after 30 seconds or so all of a sudden my event listener would stop functioning. The event was never removed, still showed up in the debugger tools, everything. It wasn’t until after over 3 days of nailing my head against the keyboard that I finally figured it out.

Why use an anonymous function? Because that allowed me to pass variables seemlessly to my functions that I wanted to call. For example:

var aNumber:Number = 3;

function(evt:Event):void {

This is just a crude example snippit, but in this case if I have a MovieClip called “aClip” and I want it to call the function “callThisFunction” on the event of if it gets clicked, but I also want to pass it a parameter “aNumber”.

It was (in my eyes) a beautiful way to handle the situation, until the AS3 garbage collector stepped onto the stage (pun intended haha).

Hope this helps some desperate AS3 programmer that surfs Google like a starving vulture in a dessert looking for the smallest scrap of meat to appease their application from sporadic behavior.

Windows System File Checker

sfc is a command line tool that I have recently stumbled upon which had its uses when I was fixing a laptop. The RAM on the computer had gone bad, thus the computer repeatedly blue screened and crashed due to the bad memory corrupting data. Once the bad RAM was removed, the system ran fine again.

The only problem is that I feared the OS system files would be corrupt from either the repeating blue screening or from the RAM corrupting application data when it was doing an IO write back to the hard drive. If the RAM was bad, it could have to potential to corrupt any number of files on your computer.

Turns out there is an application on windows that will verify the integrity of the OS system files and if a corrupt file is found it will replace it with the correct file.

The simplest of commands is “sfc /scannow” on most NT-based OSes.

I would also suggest running this if you have imaged/restored your hard drive, because of either just HD replacement, or HD failure. It provides a bit more of the “peace-of-mind”.