AS3 Garbage Collection with Closures

by Mike Welsh on September 18, 2011

I was talking with Ido about memory usage in AS3, and we discovered a small weakness in the AVM’s garbage collector. If you use a functional style of programming with lots of anonymous or nested functions, here’s something to watch out for:

import flash.display.Sprite;
import flash.events.Event;

function foo():* {
    var sprite:Sprite = new Sprite();
    sprite.addEventListener(Event.ENTER_FRAME, tick);

    // this closure creates a reference to the outer scope, foo
    return function():void { }
}

function tick(event:Event):void {
    trace("tick");
}

var func:* = foo();
System.gc();
// sprite is never garbage collected, and continues to tick

sprite will not be garbage collected, even though it’s just a local variable of foo and no other references to it exist!

[click to continue…]

{ 1 comment }

Skincraft

by Mike Welsh on June 4, 2011

My buddies Shawn Tanner and Michael Swain have released Skincraft, an awesome editor for Minecraft. Check it out on Newgrounds:

Skincraft [newgrounds.com]

Skincraft

I helped out with the 3D display of the Minecraft character, as well as the file sharing features of the Newgrounds API that allow people to upload their skins. I’ve been hard at work on the Newgrounds API for several months, and I think this is one of the best examples of it yet!

{ 2 comments }

AS2 Dithered Transition Effect

by Mike Welsh on March 27, 2011

Tom was looking for some old school effects to use in The Room Tribute game, so I cooked up some pixel-style transitions. By creating a small BitmapData and scaling it to the entire stage, you can create many fun, chunky effects that even AS2 can handle. Now Flash can look like an ancient version of Windows… :)

AS2 Dither Transition

Dithered Transitions

Click here to download the source (Flash 8+ FLA).

{ 1 comment }

Happy 20th Birthday, Street Fighter II

by Mike Welsh on March 18, 2011

I don’t have many memories from when I was very young, but one sticks out clearly in my mind. My mom was shopping at the mall, with my brother and me in tow. As we walked past the Hills department store, a blast of electronic noise caught my ear. An arcade had opened in the mall, and like moths to flame, my brother and I stormed into it. To a kid, no experience is quite as visceral as walking into an arcade. And the first thing I saw was this:

[click to continue…]

{ 2 comments }