Test Movie and AS2 Garbage Collection Hilarity

Want to scramble the Flash 8 compiler’s brain? (Or more likely your own?) Give the following class a quick whirl.

class TestArray {
  private var foo:Array = new Array();
  public function TestArray() {
    this.foo.push("bar");
    trace("this.foo.length ––> " + this.foo.length);
  }
}

I know, I know. Bad form. ‘Tis true. The class property foo isn’t really a compile-time constant. But the compiler says nary a word in protest. No errors thrown. Nada. Zip. Zero. Nothing. Which would be fine if the Flash IDE didn’t get all butterfingered on you.

But try creating a new instance of TestArray in your Flash movie and invoke “Test Movie” a few times without closing the window. The length of foo will just grow and grow and grow. It’s only cleaned up between tests if you close out the Test Movie window and start over again.

I could be wrong, but methinks I smell a compiler garbage collection issue (albeit one surrounding bad code). Shouldn’t the compiler be smart enough to let you know when you’ve done something that’s basically foolish?