Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question Best settings for Windows game with GC?

Discussion in 'Windows' started by ClosingTime, Aug 18, 2023.

  1. ClosingTime

    ClosingTime

    Joined:
    Nov 23, 2016
    Posts:
    230
    What are the best settings to minimize GC spikes in a windows game?
    I have set incremental GC, should I also set .net framework instead of 2.1?

    I still may get horrible spikes during game which literally freeze the game for half a second...
    It is mostly GC IMO.

    The spikes happen in a built version as well. Not in editor.
     
  2. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,628
    Setting to .NET Framework vs .NET Standard will not make any difference there.

    Did you try using the profiler to confirm that the freezes are GC related? How much are you allocating per frame?
     
  3. ClosingTime

    ClosingTime

    Joined:
    Nov 23, 2016
    Posts:
    230
    Yes, I did use the profiler.
    I did see the spikes correspond to GC.
    I tried to find out what I am allocating to much.
    I don't think it's something big, just a lot of little ones.
    I wasn't able to find what was causing the gradual rise in memory, then the GC drop.
    It improved a lot when I changed it to ILCPP I think, instead of mono.
    But still happen sometimes.

    How would I find a lot of small allocations?
     
  4. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,628
    Lots of small allocations is exactly what would cause garbage collector performance issues.

    Switch the profiler to hierarchy view and look for "GC.Alloc" entries.