1. Home
  2. Docs
  3. AndroidBridge
  4. Things to remember
  5. Garbage Collection

Garbage Collection

  1. Any objects created which are not in use in Unity are immediately marked for GC once they are no longer in use in Unity although they will continue to reside in Android for as long as there is any reference to them. There are two exceptions to this:
    • Objects of classes which extend any Android class
    • Objects of classes which implement any Android interfaces

    Objects of such types are kept alive because they might still be in use inside Android.

    So for example in the MainScript above almost all the objects created in BuildLayout and even objects created inside Run are automatically GC’d once they are no longer in use but MainScript object is kept alive since it implements two interfaces that Android might need to callback.

  2. Once you are sure that you don’t need special objects from types that implement or extend any Android types, you must call AndroidTerminal.Finalize(this); like done on line 78 of the code in Hello, World!.
Was this article helpful to you? Yes No

How can we help?