- Home /
Do "Dynamic Public Strings" effect iPhone Performance?
Hello, I would like to know if public strings, that are getting updated every time a user taps on object, (Once every two seconds MAX) will effect the performance of the game on iOS? Should i make these strings private? Or does it not matter?
Thanks Daniel
Answer by Jamora · Jul 25, 2013 at 04:01 PM
It matters in the sense that each string that is changed creates garbage (the old string), which Unity must then, at some point clean up. This is called Garbage Collection, and every time it is done it takes a lot of CPU time, so the user might notice lag.
You should consider using the System.StringBuilder class for strings that are frequently changed, because it does not create garbage.
@Jamora Excellent, Do old strings get gotten rid of at scene change or only at application quit? Because the user might tap less than 30 times over the course of my 3D menu scene lol!
Is there a way to clean it up after every change? That seems like it would be useful for me because the user doesn't even tap that often throughout the menu or would this lag? If it would lag how bout at the loading screen? Whilst loading a level?
Also one last thing, Is there a difference between public and private strings? In performance respects? Or is it just dealing with old strings?
Sorry Unity was down for a $$anonymous$$ute! So Do you have any thoughts on the comments above? Thanks
Thoughts keep co$$anonymous$$g at me too... but I use the edit button =)
No performance difference between public and private strings. As they're just visibity modifiers.
Garbage gets collected when the memory heap is almost full, you can read more about this in the GC link in my answer and following up at memorymanagement.org
You can not force Unity to make a GC, but you can tell Unity at an appropriate time to see if there is need for one by using System.GC()
Your answer
Follow this Question
Related Questions
Unity Screen.SetResolution gives me black screen on iPhone 4S 1 Answer
Performance of C# Events on iPhone/Android 1 Answer
Performance lag every 1 second on iphone 4s 2 Answers
Using Conditional Compilers? 1 Answer
performance query 1 Answer