[Memory Test] BitmapData.clone()
BitmapData.clone() を行った場合、dispose しなくても、メモリ使用量は増えない。
/**
* Copyright clockmaker ( http://wonderfl.net/user/clockmaker )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/bnZi
*/
package
{
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.InteractiveObject;
import flash.display.Sprite;
import flash.events.ContextMenuEvent;
import flash.events.Event;
import flash.events.IEventDispatcher;
import com.flashdynamix.utils.SWFProfiler;
[SWF(width=465, height=465, frameRate=60)]
public class Main extends Sprite
{
//----------------------------------------------------------
//
// Constructor
//
//----------------------------------------------------------
public function Main()
{
orijinal = new BitmapData(465, 465);
canvas = new Bitmap();
addChild(canvas);
addEventListener(Event.ENTER_FRAME, enterFrameHandler);
setupSWFProfiler(this);
}
//----------------------------------------------------------
//
// Property
//
//----------------------------------------------------------
private var canvas:Bitmap;
private var orijinal:BitmapData;
//----------------------------------------------------------
//
// Function
//
//----------------------------------------------------------
protected function enterFrameHandler(event:Event):void
{
var clone:BitmapData = orijinal.clone();
clone.perlinNoise(100 * Math.random(), 100 * Math.random(), 1, 1, false, true);
canvas.bitmapData = clone;
}
private function setupSWFProfiler(context:InteractiveObject):void
{
SWFProfiler.init(context);
(context.contextMenu.customItems[0] as IEventDispatcher).dispatchEvent(new ContextMenuEvent(ContextMenuEvent.MENU_ITEM_SELECT));
}
}
}