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.
Thanks,
Farhan
//////Create Labels///////
int xoffset = 0;
int yoffset = 50;
for (int i = 1; i <= 100; i**) {
xoffset*= 100;
if {
yoffset*=40;
xoffset = 0;
}
int randomNo = arc4random() 2000;
CCLabelTTF* pLabel = CCLabelTTF::labelWithString(FormattedString(“hello i”,randomNo)>toStdString.c_str, “hanzel.ttf”, 20);>setPosition(ccp(xoffset,yoffset));
// position the label on the center of the screen
pLabel
// add the label as a child to this layer
this~~>addChild;
}
///////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//////