1

I am trying to suspend (or reduce) Garbage Collection during a critical timing section of our application within Unity3D 5.6

I am trying to set the Latency Mode to 'LowLatency', but upon checking the GCSettings.LatencyMode it only shows the value Interactive

   GCSettings.LatencyMode = GCLatencyMode.LowLatency;
GregM
  • 3,624
  • 3
  • 35
  • 51

1 Answers1

2

Unity3D 5.6 did not have the Interactive value but you can get that when you download Unity 2017 since this version of Unity supports. Download it then enable .NET 4.6 You can see how to enable that from this post.

Remember that this is Unity, it should compile but that does not mean it will work. If you don't want Garbage Collection to run, do not allocate memory when game is running. Do that in the beginning of the game then use Object Pooling to handle your GameObjects.

Programmer
  • 121,791
  • 22
  • 236
  • 328
  • .net 3.5 does have Interactive https://msdn.microsoft.com/en-us/library/system.runtime.gclatencymode(v=vs.90).aspx – GregM Sep 29 '17 at 19:07
  • 1
    Yes, I know that. Unity uses Mono not Microsoft's implementation. To make it worse, the old version uses old Mono version which did not implement few API's. Unity 2017 fixed that. Just try that before commenting. – Programmer Sep 29 '17 at 19:10
  • First please understand I appreciate your help... please also appreciate that switching an entire platform, on a large project is a bit more work then asking for a bit more clarification. your 'try that before commenting' isn't appreciated nor helpful... since the MSDN documentation and compilation both point to me having a solution that works... Furthermore, 'Interactive' works perfectly fine in 5.6, as that is the default value returned. Setting to 'LowLatency' as I outlined in the original question is what does not work. – GregM Sep 30 '17 at 18:19
  • *"your 'try that before commenting' isn't appreciated nor helpful"* For the past few months, when I leave an answer, some OPs just like you comments with *"That will not work"* or *"That will not work"* or they just say something that shows that they don't even care about the answer. I got tired of it and that's why I just tell people to try an answer before commenting to save me my time. It's not made as an insult or anything. – Programmer Sep 30 '17 at 19:01
  • In my answer, I meant to say "LowLatency" not "Interactive" and I don't even know how "Interactive" got there instead. Please understand this: C# implementation is not the-same with the one from Microsoft. Your Unity version uses old Mono which did [**not**](https://forums.xamarin.com/discussion/40524/gcsettings-latencymode-is-not-changing) implement that. By downloading Unity 2017, you will that feature otherwise it won't work. I am not forcing you to download new version of Unity. I am just telling you why it's not working and what you can do to make it work. – Programmer Sep 30 '17 at 19:05
  • Unity 2017 does not change the way GCSettings.LatencyMode works. The code above rendered the _exact_ same results with 'Experimental.net 4.6' selected in the player settings. This is not an accepted answer. – GregM Oct 03 '17 at 20:25