Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

Topics - smartie

Pages: [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:

  1. stringBuilder.Remove(0, _stringBuilder.Length);
  2. stringBuilder.Append(DistanceCurrentScore);
  3. string textScore = stringBuilder.ToString();
  4. 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?

Pages: [1]