Share 'Performance' on Delicious Share 'Performance' on Facebook Share 'Performance' on Google Bookmarks Share 'Performance' on Twitter

  1. Source and SWF
  2. Initial memory usage
  3. Memory after layouts added
  4. Memory after layout reference removed
  5. Memory after all boxes removed
  6. Leave a Comment

Performance

Layouts is performance and memory optimized. All references are removed entirely when you remove a layout reference. There is an example application that you may use (or modify and use) to track the memory usage of Layouts. You will need a profiler to do so. A profiler is shipped with FDT or FlashBuilder.

This page shows source code of the example, the SWF and different screenshots of the memory usage. The test application source code is also available on GitHub.

Source and SWF

MemoryTest.swf
  • Hit the A key to add the six diffent layouts.
  • Hit the C to remove the internal layout reference.
  • Hit the R to remove all boxes from the movie.
MemoryTest.as
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
package layout.memory {
  import org.as3commons.ui.layout.framework.ILayout;
  import org.as3commons.ui.layout.shortcut.*;
  import flash.display.Sprite;
  import flash.events.Event;
  import flash.events.KeyboardEvent;
  import flash.ui.Keyboard;

  public class MemoryTest extends Sprite {
    private var _layout : ILayout;

    public function MemoryTest() {
      addEventListener(Event.ADDED_TO_STAGE, init);
    }

    private function init(event : Event) : void {
      removeEventListener(Event.ADDED_TO_STAGE, init);
      stage.addEventListener(KeyboardEvent.KEY_DOWN, keyDown);
    }

    private function keyDown(event : KeyboardEvent) : void {
      if (event.keyCode == Keyboard.A) add();
      if (event.keyCode == Keyboard.C) clearReference();
      if (event.keyCode == Keyboard.R) remove();
    }
   
    private function add() : void {
      remove();
      _layout = hlayout(
        "maxItemsPerRow", 3,
        "hGap", 10, "vGap", 10,
        createHGroup(),
        createHLayout(),
        createTable(),
        createVGroup(),
        createVLayout(),
        createDynTable()
      );
      _layout.layout(this);
    }
   
    private function clearReference() : void {
      _layout = null;
    }
   
    private function remove() : void {
      while (numChildren) removeChildAt(0);
    }
   
    private function createHGroup() : ILayout {
      var color : uint = Math.round(Math.random() * 0xFFFFFF);
      return hgroup(
        "gap", 2,
        MemoryBox.create(10, color)
      );
    }
   
    private function createHLayout() : ILayout {
      var color : uint = Math.round(Math.random() * 0xFFFFFF);
      return hlayout(
        "maxItemsPerRow", 10, "hGap", 2, "vGap", 2,
        MemoryBox.create(100, color)
      );
    }
   
    private function createVGroup() : ILayout {
      var color : uint = Math.round(Math.random() * 0xFFFFFF);
      return vgroup(
        "minWidth", 118, "gap", 2,
        MemoryBox.create(10, color)
      );
    }
   
    private function createVLayout() : ILayout {
      var color : uint = Math.round(Math.random() * 0xFFFFFF);
      return vlayout(
        "maxItemsPerColumn", 10, "hGap", 2, "vGap", 2,
        MemoryBox.create(100, color)
      );
    }
   
    private function createTable() : ILayout {
      var color : uint = Math.round(Math.random() * 0xFFFFFF);
      return table(
        "numColumns", 10, "hGap", 2, "vGap", 2,
        MemoryBox.create(100, color)
      );
    }
   
    private function createDynTable() : ILayout {
      var color : uint = Math.round(Math.random() * 0xFFFFFF);
      return dyntable(
        "maxContentWidth", 118, "hGap", 2, "vGap", 2,
        MemoryBox.create(100, color)
      );
    }
  }
}
MemoryBox.as
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
package layout.memory {
  import flash.display.Sprite;
 
  public class MemoryBox extends Sprite {
    public static function create(numBoxes : uint, color : uint) : Array {
      var array : Array = new Array();
      for (var i : uint; i < numBoxes; i++) {
        array.push(new MemoryBox(color));
      }
      return array;
    }

    public function MemoryBox(color : uint) {
      with (graphics) {
        clear();
        beginFill(color);
        drawRect(0, 0, 10, 10);
      }
    }
  }
}

Initial memory usage

Memory after layouts added

The main layout is still referenced in a local variable.

Memory after layout reference removed

Everything the layout did store is removed from the memory.

Memory after all boxes removed

There is nothing left.



Leave a Comment

You have a question or have experienced an issue? Please post it in the forum: http://sibirjak.tenderapp.com/ in order to make the discussion available at a more central place.