Search Unity

Change the garbage collector used by Unity ?

Discussion in 'Scripting' started by Despay, May 7, 2017.

  1. Despay

    Despay

    Joined:
    Apr 24, 2016
    Posts:
    2
    Hello,

    I would like to know if it was possible to change the implementation of the garbage collection used in unity.

    For example, in Java, there are some non blocking garbage collection. Is there some equivalent and usable for unity in c# world ?

    Thanks.
     
  2. methos5k

    methos5k

    Joined:
    Aug 3, 2015
    Posts:
    8,712
    I don't think so.. It's on the roadmap of things to be upgraded (generational GC), but nothing that I'm aware of beyond that.
     
  3. Despay

    Despay

    Joined:
    Apr 24, 2016
    Posts:
    2
    Too bad :(
    thank you for answering
     
  4. methos5k

    methos5k

    Joined:
    Aug 3, 2015
    Posts:
    8,712
    Ya, I think everyone will be happy when the new GC is implemented :) But we survive until then.. :)
     
  5. IgorAherne

    IgorAherne

    Joined:
    May 15, 2013
    Posts:
    393
    Unity 2019.1 comes with an Incremental Garbage Collection, that smears-out any GC spikes over many frames:
    https://blogs.unity3d.com/2018/11/26/feature-preview-incremental-garbage-collection/

    It's in Alpha now, but if someone (like me) really needs it before his/her deadline, there is 1 issue you might face when building for Android:
    - keystore passwords not being recognised as you type them, or perhaps, only in a Development Build.

    To solve this for now, I did the following:
    1) used cmd and java's "keytool" to generate an RSA keystore (google or youtube how to do it)
    2) Selected the generated keystore from ProjectSettings/Player, but didn't enter passwords, nor selected the Alias.
    3) Placed the following code in Editor, and ran it:

    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEditor;
    3. public class BuildSettings_Set_KeystoreVals : MonoBehaviour
    4. {
    5.     const string androidKeystorePass = "YourPassword";
    6.     const string androidKeyaliasName = "YourKeystoreKeyAlias";
    7.     const string androidKeyaliasPass = "YourAliasPassword";
    8.  
    9.     [MenuItem("Build/Set_KeystoreVals")]
    10.     static void Set_KeystoreVals(){
    11.         PlayerSettings.Android.keystorePass = androidKeystorePass;
    12.         PlayerSettings.Android.keyaliasName = androidKeyaliasName;
    13.         PlayerSettings.Android.keyaliasPass = androidKeyaliasPass;
    14.     }
    15. }


    4) Built the application in Mono
     
    Last edited: Jan 21, 2019
  6. lordofduct

    lordofduct

    Joined:
    Oct 3, 2011
    Posts:
    8,534
    interesting...

    though honestly, with how we've written our code up to this point, GC hasn't been an issue for us

    I still look forward to it. I like the prospect of possibly other GC engines down the line.