如何从持有者和Flash Player内存中的bitmapData中删除位图?
var _myThumb:Bitmap;
var _myThumbData:BitmapData;
var bitmap:Bitmap
//
function createThumbs()
{
_myThumbData = new BitmapData(pic.picdefault.width,pic.picdefault.height,false,0xffffff);
//
picthumbs.t1.holder.addChild(createBitmap(_myThumbData));
picthumbs.t2.holder.addChild(createBitmap(_myThumbData));
picthumbs.t3.holder.addChild(createBitmap(_myThumbData));
picthumbs.t4.holder.addChild(createBitmap(_myThumbData));
picthumbs.t5.holder.addChild(createBitmap(_myThumbData));
}
function createBitmap(bmd:BitmapData):Bitmap
{
var bitmap:Bitmap = new Bitmap(bmd);
bitmap.smoothing = true;
setSize(bitmap, bmd.width, bmd.height, 94, 94);
return bitmap;
}
function setSize(target:DisplayObject, contentWidth:Number, contentHeight:Number, targetWidth:Number, targetHeight:Number):void {
var w:Number = targetWidth;
var h:Number = targetHeight;
var containerRatio:Number = targetWidth / targetHeight;
var imageRatio:Number = contentWidth / contentHeight;
if (containerRatio < imageRatio) h = w / imageRatio;
else w = h * imageRatio;
target.width = w;
target.height = h;
target.x = (targetWidth - w) * .5;
target.y = (targetHeight -h) * .5;
}
//
function createThumbnail()
{
_myThumbData.draw(pic.picdefault);
}
答案 0 :(得分:1)
假设持有人只是一个空的MovieClip,那么你可以简单地去:
picthumbs.t1.holder.removeChildAt(0);
这将删除对Bitmap的引用,从而使其符合垃圾回收的条件。由于BitmapData仅由Bitmap引用,并且不再引用Bitmap,因此它也将从内存中删除。
答案 1 :(得分:0)