cacheAsBitmapは参照するだけでメモリーを喰う。

by mtok forked from flash on 2009-11-27 (diff: 41)
♥0 | Line 40 | Modified 2009-11-27 18:47:28 | MIT License
play

ActionScript3 source code

/**
 * Copyright mtok ( http://wonderfl.net/user/mtok )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/jzPf
 */

<?xml version="1.0" encoding="utf-8"?>
<!-- forked from mtok's flash on 2009-11-27 -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" applicationComplete="appCompHandler()">
    <mx:Script>
    <![CDATA[
    import mx.core.UIComponent;
    import mx.events.FlexEvent;
    import flash.display.Sprite;
    import flash.system.System;
    private function appCompHandler():void{
        var comp:UIComponent = new UIComponent();
        canvas.addChild(comp);
        
        var sprites:Array = [];
        var num:int = 500;
        for(var i:int = 0; i < num; i++){
            var s:Sprite = new Sprite();
            s.graphics.beginFill(0,0xff0000);
            s.graphics.drawCircle(0,0,20);
            s.graphics.endFill();
            comp.addChild(s);
            sprites.push(s);
        }
        
        println(String(System.totalMemory));
        
        for each(s in sprites){
            s.cacheAsBitmap;
            
            //s.cacheAsBitmap = true;
            
            //cacheAsBitmapの値がfalseにも関わらず、
            //こうやってcacheASBitmapを参照するだけで
            //trueに設定したときと同じだけメモリーが消費されるっぽい
        }
        println(String(System.totalMemory));
    }
    
    private function print(str:String):void{
        taOutput.text = taOutput.text.concat(str);    
    }
    private function println(str:String):void{
        print(str);
        print("\n");    
    }
    
    ]]>
    </mx:Script>
    <mx:TextArea width="100%" height="50%" id="taOutput" ></mx:TextArea>
    <mx:Canvas width="100%" height="100%" id="canvas" />
</mx:Application>