Invalid BitmapData error - Why?

I have created a document class with this code:

package {
    //
    import flash.display.Sprite
    import flash.display.BitmapData;
    //
    public class main extends Sprite {
        //
        var allData:Array = new Array();
        //
        public function main() {
            var n:int;
            for (n=0;n<9000;n++) {
                var colour:int = Math.round(Math.random()*0xFFFFFF);
                var myBD:BitmapData = new BitmapData(2, 2, false, colour);
                allData[n] = myBD;
            }
        }
    }
}

This works fine and creates 9000 BitmapData objects.

However, if you change the loop size to 10000, you will get an Invalid BitmapData error and sometimes (for me anyway) Flash will continually display dialog boxes the content of which I cannot actually see (might be a Vista thing).

Note:all of the code is important - if you comment out the line which assigns the data to the array everything seems to work fine. I’ve never been more confused…

Anyone got any ideas?