Using cacheAsBitmap on Textfield lead to memory leak when the textfield is part of Sprite and call addChild / removeChild for this Sprite.
The bug was found on a real project and it was hard to isolate only that part of the code , but below is example with similar action.
What is interesting , when garbage collector is invoked , part of the memory is released , but always more than the previous level i.e. first start with 70 MB , rise to 120 MB, GC is invoke, memory drop to 90 MB start to rise to 130 , drop to 100 MB and so on which lead to memory leak.
The target is C++ using hxcpp 4.0.64 , test on iOS and windows native . Here is screenshot from XCode ( using Openfl : 8.9.5 , Lime 7.6.3 )
If set txt.cacheAsBitmap = false;
there is no memory leak.
Here is example code
var tmr:Timer = new Timer(100);
var sp:Sprite = new Sprite();
var bmp:Bitmap = new Bitmap();
var txt:TextField;
public var s_sp:Sprite;
public function new()
{
super();
onCheckStatusOK();
}
private function onCheckStatusOK() : Void
{
s_sp = new Sprite();
this.addChild(s_sp);
bmp.bitmapData = Assets.getBitmapData("assets/test.png");
sp.addChild(bmp);
txt = new TextField();
sp.addChild(txt);
txt.cacheAsBitmap = true;
tmr.run = function() {
if(s_sp.contains(sp))
s_sp.removeChild(sp);
else
s_sp.addChild(sp);
}
}