1
NGUI 3 Support / Avoiding the garbage collector with UILabel.text
« on: August 28, 2014, 11:42:33 AM »
Is there any way of setting the text in a UILabel without allocating memory?
We have some code that is setting the current score every frame like this like this:
And this causes memory allocations every frame because UILabel.text is a string, which is immutable, so has to be recreated every time we want it to change.
Is there an alternative way of setting a text value for a UILabel which doesn't allocate memory?
We have some code that is setting the current score every frame like this like this:
- stringBuilder.Remove(0, _stringBuilder.Length);
- stringBuilder.Append(DistanceCurrentScore);
- string textScore = stringBuilder.ToString();
- scoreLabelHUD.text = textScore;
And this causes memory allocations every frame because UILabel.text is a string, which is immutable, so has to be recreated every time we want it to change.
Is there an alternative way of setting a text value for a UILabel which doesn't allocate memory?