
Код AS3:
package app
{
import flash.system.Security;
import flash.system.System;
import flash.display.*;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.text.*;
import flash.filters.ColorMatrixFilter;
import flash.geom.Point;
public class MemoryTest extends Sprite
{
protected var _leftBitmap:Bitmap;
protected var _rightBitmap:Bitmap;
protected var _convertedBitmap:Bitmap;
protected var _memoryInfo:TextField;
public function MemoryTest()
{
_leftBitmap = getBitmap(LeftImage);
_rightBitmap = getBitmap(RightImage);
_memoryInfo = new TextField();
stage.addChild(_memoryInfo);
stage.addEventListener(MouseEvent.MOUSE_DOWN,mouseDownHandler);
}
protected function getBitmap(src:Class)
{
var image = new src();
var bd = new BitmapData(image.width,image.height);
bd.draw(image);
var bm = new Bitmap(bd);
return bm;
}
protected function mouseDownHandler(evt:MouseEvent=null)
{
if (_convertedBitmap)
{
clearBitmap(_convertedBitmap);
_convertedBitmap.parent.removeChild(_convertedBitmap);
}
_memoryInfo.text = "Memory: "+System.totalMemory/(1024);
_memoryInfo.autoSize = "left";
var leftBitmapMatrix = new Array();
leftBitmapMatrix = leftBitmapMatrix.concat([0.299, 0.587, 0.114, 0, 0]); // red
leftBitmapMatrix = leftBitmapMatrix.concat([0, 0, 0, 0, 0]); // green
leftBitmapMatrix = leftBitmapMatrix.concat([0, 0, 0, 0, 0]); // blue
leftBitmapMatrix = leftBitmapMatrix.concat([0, 0, 0, 1, 0]); // alpha
var rightBitmapMatrix = new Array();
rightBitmapMatrix = rightBitmapMatrix.concat([0, 0, 0, 0, 0]); // red
rightBitmapMatrix = rightBitmapMatrix.concat([0, 1, 0, 0, 0]); // green
rightBitmapMatrix = rightBitmapMatrix.concat([0, 0, 1, 0, 0]); // blue
rightBitmapMatrix = rightBitmapMatrix.concat([0, 0, 0, 1, 0]); // alpha
_convertedBitmap = new Bitmap(new BitmapData (_leftBitmap.width, _leftBitmap.height, true, 0));
var proccessedLeftBitmap = getProccessedBitmap(_leftBitmap,new ColorMatrixFilter(leftBitmapMatrix));
var proccessedRightBitmap = getProccessedBitmap(_rightBitmap,new ColorMatrixFilter(rightBitmapMatrix));
_convertedBitmap.bitmapData.draw(proccessedLeftBitmap, null, null, BlendMode.ADD);
_convertedBitmap.bitmapData.draw(proccessedRightBitmap, null, null, BlendMode.ADD);
addChild(_convertedBitmap);
clearBitmap(proccessedLeftBitmap);
clearBitmap(proccessedRightBitmap);
}
protected function clearBitmap(bitmap:Bitmap)
{
if (bitmap.bitmapData)
{
bitmap.bitmapData.dispose();
bitmap.bitmapData = null;
bitmap = null;
}
}
protected function applyFilter(bitmap:Bitmap,colorMatrixFilter:ColorMatrixFilter)
{
var filters:Array = new Array();
filters.push(colorMatrixFilter);
bitmap.filters = filters;
}
protected function getProccessedBitmap(srcBitmap:Bitmap,filter:ColorMatrixFilter)
{
var proccessedBitmapData = srcBitmap.bitmapData.clone();
var proccessedBitmap = new Bitmap(proccessedBitmapData);
applyFilter(proccessedBitmap,filter);
return proccessedBitmap;
}
}
}
Если закоментировать строчку applyFilter(proccessedBitmap,filter); в функции getProccessedBitmap(srcBitmap:Bitmap,filter:ColorMatrixFilter), память почти не увеличиваеться, а с ней стремительно растет после каждого нажатия кнопки мышки...