azrafe7

Lambda.indexOf() Leak in Flash

Dec 10th, 2013
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class Main
  2. {
  3.     static private var textField:TextField;
  4.     static private var array:Array<Int>;
  5.    
  6.     public function new() {
  7.         main();
  8.     }
  9.    
  10.     public static function main()
  11.     {
  12.         var stage:Stage = Lib.current.stage;
  13.         stage.addEventListener(KeyboardEvent.KEY_DOWN, onKeyDown);
  14.         stage.addEventListener(Event.ENTER_FRAME, onEnterFrame);
  15.        
  16.         textField = new TextField();
  17.         var format:TextFormat = new TextFormat();
  18.         format.font = "_typewriter";
  19.         format.color = 0xFFFFFF;
  20.         textField.multiline = true;
  21.         textField.autoSize = TextFieldAutoSize.LEFT;
  22.         textField.defaultTextFormat = format;
  23.         textField.setTextFormat(format);
  24.        
  25.         stage.addChild(textField);
  26.        
  27.         array = new Array<Int>();
  28.         for (i in 0...100) array.push(i);
  29.     }
  30.    
  31.     public static function onEnterFrame(evt:Event):Void
  32.     {
  33.         textField.text = "Mem: " + System.totalMemory / 1024 / 1024 + " Mb\n" +
  34.                          "\nUsing Lambda.indexOf() - every frame - \non the same Array of " + array.length + " elements.\n";
  35.        
  36.         Lambda.indexOf(array, Std.int(Math.random() * array.length));       // leaks memory in flash
  37.        
  38.         //untyped array.indexOf(Std.int(Math.random() * array.length));     // no leaks
  39.     }
Advertisement
Add Comment
Please, Sign In to add comment