![]() |
|
||||||||||
|
|
|
|||||
|
Регистрация: May 2008
Сообщений: 2
|
Подскажите пожалуйста почему растет память
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; } } } |
|
|||||
|
Вы клонируете битмапу и сохраняете на неё ссылки в экземпляре Bitmap. Конечно, память будет расти.
__________________
Тут мужик танцует и поёт про флэш |
|
|||||
|
Регистрация: May 2008
Сообщений: 2
|
Цитата:
и очищаю... а память всеравно растет ![]() Знакомый попробывал скомпилировать у себя на Flash CS3 у него работает немного по другому, память увеличиваеться до определенного момента, а потом очищаеться, я компилировал на Flash CS5 у меня не очищаеться... бред какой-то... Добавлено через 18 часов 45 минут Действительно проблема была в ссылках на Bitmap 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; protected var _leftBitmapMatrix:Array; protected var _rightBitmapMatrix:Array; protected var _testFilter:*; public function MemoryTest() { _leftBitmap = getBitmap(LeftImage); _rightBitmap = getBitmap(RightImage); _memoryInfo = new TextField(); stage.addChild(_memoryInfo); _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 _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 stage.addEventListener(MouseEvent.MOUSE_DOWN,mouseDownHandler); applyFilter(_leftBitmap,new ColorMatrixFilter(_leftBitmapMatrix)); applyFilter(_rightBitmap,new ColorMatrixFilter(_rightBitmapMatrix)); } 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"; _convertedBitmap = new Bitmap(new BitmapData (_leftBitmap.width, _leftBitmap.height, true, 0)); _convertedBitmap.bitmapData.draw(_leftBitmap, null, null, BlendMode.ADD); _convertedBitmap.bitmapData.draw(_rightBitmap, null, null, BlendMode.ADD); addChild(_convertedBitmap); } protected function clearBitmap(bitmap:Bitmap) { if (bitmap.bitmapData) { bitmap.bitmapData.dispose(); bitmap.filters = []; bitmap.bitmapData = null; bitmap = null; } } protected function applyFilter(bitmap:Bitmap,colorMatrixFilter:*) { var filters:Array = new Array(); filters.push(colorMatrixFilter); bitmap.filters = filters; } protected function getProccessedBitmap(srcBitmap:Bitmap,filter:*) { var proccessedBitmapData = srcBitmap.bitmapData.clone(); var proccessedBitmap = new Bitmap(proccessedBitmapData); applyFilter(proccessedBitmap,filter); return proccessedBitmap; } } } Спасибо Последний раз редактировалось antprobe; 20.05.2010 в 11:39. |
![]() |
![]() |
Часовой пояс GMT +4, время: 14:28. |
|
|
« Предыдущая тема | Следующая тема » |
|
|