cocos2d-x Custom TTF fonts causing low memory on android

cocos2d-x Custom TTF fonts causing low memory on android
0.0 0


Hi Everyone,

I am developing a game in which I have to make and update a lot of labels after every 2-3 seconds. Everything works fine on the iOS but on the android the app starts to get low memory after some label updates. What I do is create around 100 custom ttf labels using CCLabelTTF::labelWithString method passing my custom ttf font name and it works fine as expected. After every 2-3 seconds I update all the labels using the CCLabelTTF setString method. The problem I am facing is that after updating the labels for about 30-40 times the app starts to kill all the background apps because of low memory on my nexus1. I tried using built-in font like arial and the app worked fine without any problem. I suppose this is an issue related to custom ttf fonts on android only. I would really appreciate if anyone could help me out with this issue. I also made a stress test to confirm this problem. Code is pasted below.


//////Create Labels///////
int xoffset = 0;
int yoffset = 50;
for (int i = 1; i <= 100; i**) {
xoffset*= 100;
if {
xoffset = 0;
int randomNo = arc4random() 2000;
CCLabelTTF* pLabel = CCLabelTTF::labelWithString(FormattedString(“hello i”,randomNo)>toStdString.c_str, “hanzel.ttf”, 20);
// position the label on the center of the screen
// add the label as a child to this layer
///////Create Labels/////////

/////update labels using button/////
for {
int randomNo = arc4random 1000;
CCLabelTTF *plabel = (CCLabelTTF *)getChildByTag(i);
plabel->setString(FormattedString(“hello d %i”, i * j, randomNo)~~>toStdString().c_str());

/////update labels using button//////


OK, It looks like a new bug.
Bug #758 created.
Could you tell me the android version running on your nexus1?


The version number is 2.3.4.


some progress or new information about this bug?

I think I have the same problem.


Hi Milda,

The following link suggests a workaround which works fine for me.


Hi Farhan,
thanks for workaround, its work for me too. Plus really nice memory list.

adb shell dumpsys meminfo 

For other users I uploaded this workaround.


Thank you.