FPS script and .net string release overhead

The following is from unify community fps script

void Update()

{

float fps = accum/frames;
string format = System.String.Format(“{0:F2} FPS”,fps);
guiText.text = format;

}

Will the overhead of releasing the string objects affect the actual fps?
e.g. There could be 30 string objects per second to release.

The mono garbage collector (GC) will collect strings and other objects not referenced anymore.

A GC locks all threads before it collects garbage, which means that your game thread is not progressed during garbage collection.

Whether or not GC affects the FPS?

Try to check for exceptional high spikes in the unity profiler. If none are to be found, the GC runs are pleasant, and you are in the clear - for now.

Otherwise, you need to figure out whether the spikes are due to GC runs.
In this case you can do as we do in the game I am working on:

  • Use GC.CollectionCount to detect when the garbage collector has just run and flash it on the screen. In this way we know if FPS drops are due to GC or not.
  • Have a FPS counter that only create a new string per second. The string contains min, average and max values for the FPS during the last seconds. The string is displayed each frame.

Hope it helps,

Keld