I was learning some Haxe with openfl and adding images and text to the screen and did so.
I started by creating a project through command line with openfl, added an update frame event listener, a picture and text using
addChild(myText);
stage.addEventListener(Event.ENTER_FRAME, update);
bonzi = new Bitmap(Assets.getBitmapData("assets/bonzi.jpg"));
addChild(bonzi);
and in the update() method I put:
bonzi.rotation += 4;
myText.text = bonzi.rotation;
This works like expected, bonzi.jpg rotating around top-left corner and in the same corner a textfield displaying the rotation.
Now here's the problem: If I let this run for ~30 sec the program has eaten up 1.8 Gb of my memory and runs then very slowly, hogging now exactly 1863.6 Mb of memory. Eventually myText disappeared after the program ran really slow for about another 20 sec, making bonzi rotate almost normally but still hogging the same amount of memory. Even if I add
if (bonzi.rotation >= 360) bonzi.rotation -= 360;
to the update-loop to make sure the rotation keeps within the [0;360] range, same thing happens.
Strangely, though, if I change anything so that myText does not change in the update method memory usage stays normal (15-30 Mb) e.g. changing Std.string(bonzi.rotation) to Std.string("Hi") or bozi.rotation += 4 to bozi.rotation = 4.
I'm at loss to why this happens. This is very inconvenient since I plan to use text-fields a lot in the future.
EDIT: My full code run through openfl via cpp - test
package;
import openfl.display.Sprite;
import openfl.display.Bitmap;
import openfl.Assets;
import openfl.text.TextField;
import openfl.events.Event;
import openfl.system.System;
class Main extends Sprite {
public var bonzi:Bitmap;
public var myText:TextField = new TextField();
public function new() {
super();
addChild(myText);
stage.addEventListener(Event.ENTER_FRAME, update);
bonzi = new Bitmap(Assets.getBitmapData("assets/bonzi.jpg"));
addChild(bonzi);
bonzi.rotation = 260;
myText.text = Std.string(bonzi.rotation);
}
public function update(e:Event):Void {
bonzi.rotation += 4;
if (bonzi.rotation >= 180) bonzi.rotation -= 360;
myText.text = Std.string(bonzi.rotation);
}
}