Advertisement
YellowAfterlife

Does flash.utils.setTimeout leak memory? No, it doesn't.

Oct 24th, 2013
283
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Haxe 0.74 KB | None | 0 0
  1. import flash.events.TimerEvent;
  2. import flash.system.System;
  3. import flash.utils.Timer;
  4. ///
  5. class Main {
  6.     static function main():Void {
  7.         var timer:Timer = new Timer(1000);
  8.         timer.addEventListener(TimerEvent.TIMER, onTimer);
  9.         timer.start();
  10.     }
  11.     static function getOne(v:Dynamic):Void {
  12.         untyped __global__["flash.utils.setTimeout"](function() { v = null; }, 10);
  13.     }
  14.     static function onTimer(_):Void {
  15.         for (i in 0 ... 1024) getOne(new One());
  16.         // Show memory usage:
  17.         trace(System.totalMemory / (1024 * 1024) + "MB");
  18.     }
  19. }
  20. /// Holds a useless 1024-element array of integers
  21. class One {
  22.     public var ints:Array<Int>;
  23.     public function new() {
  24.         ints = []; for (i in 0 ... 1024) ints.push(Std.int(Math.random() * 0x10000));
  25.     }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement