I’m trying to modify my bitmap to change their pixels to a random color. This is the way I do it (I’m using the FlashPunk library):
private var _v:Point = new Point;
private var _speed:Point = new Point(200, 200);
private var _bmpData:BitmapData = new BitmapData(24, 24, false, 0x000000)
private var _bmpImage:Image = new Image(_bmpData);
public function Player(p:Point)
{
graphic = _bmpImage;
x = p.x;
y = p.y;
}
override public function update():void
{
updateMovement();
updateCollision();
super.update();
}
override public function render():void
{
_bmpData.lock();
for (var j:int = 0; j < _bmpData.height; j++) {
for (var i:int = 0; i < _bmpData.width; i++) {
_bmpData.setPixel(i, j, FP.rand(0xffffff));
}
}
_bmpData.unlock();
graphic = new Image(_bmpData);
super.render();
}
So ok, the function that does this is render(), but in the line
graphic = new Image(_bmpData);
I get new memory for graphic, and this translate into a memory leak in the game. Here is an image of this:

And as you can see, the MEM: part is constantly increasing :/
Anyone knows another way to do this?
At the end I only had to replace
graphic = new Image(_bmpData);for
_bmpImage.updateBuffer();and now it works fine 🙂Here is the doc for that function
Cheers!