メモリ管理 – Flex
FlashでもFlexでもメモリリークには気をつけないといけません。 Flex Builderなら強力なプロファイラがあるからいいけど、 FlashDevelopとかでFlexアプリを作る場合の、メモリ使用量の監視と強制GCを行うコード。
1 2 3 4 5 6 7 |
<mx:Label id="totalMemory" text="{(System.totalMemory / 1024) + 'KB'}" render="totalMemory.text = (System.totalMemory / 1024) + 'KB'" /> <mx:Button id="gcButton" label="force garbage collection" click="System.gc()" /> |
System.totalMemoryはFlashPlayerのメモリ使用量、 System.gc()でガベージコレクションプロセスを強制します。(デバッグ版FlashPlayerのみ) Flas…