Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We are updating our Terms of Service for all Unity subscription plans, effective October 13, 2022, to create a more streamlined, user-friendly set of terms. Please review them here: unity.com/legal/terms-of-service.
    Dismiss Notice
  3. Have a look at our Games Focus blog post series which will show what Unity is doing for all game developers – now, next year, and in the future.
    Dismiss Notice

Application.UnLoad is not working on Android?

Discussion in 'Android' started by tinyant, May 26, 2021.

  1. tinyant

    tinyant

    Joined:
    Aug 28, 2015
    Posts:
    117
    I am using Unity3d As library for my Android app. we need to enter and exit Unity so many times,so we want to try just unload UnityEngine use Application.Unload ,But we found Application.Unload not release memory when call unload.we use Android Studio to check if memory was released when call Application.Unload

    we test memory problem just with unity's example(Android)

    https://github.com/Unity-Technologies/uaal-example
    we replace SimpleScene with more complex scene to find if unity real release it's memory when call Application.Unload


    Unity 2019.4.18f1(64-bit)
    BackEnd:Mono Net2.0


    We need some Help Thanks!


    Mono.apk
    https://www.dropbox.com/s/l3s9nj0dyeas60q/app-debug-Mono.apk?dl=0
     

    Attached Files:

    Last edited: Jul 8, 2021
  2. tinyant

    tinyant

    Joined:
    Aug 28, 2015
    Posts:
    117
    I tried Mono .Net2.0,.Net4.0 and IL2CPP

    all of them can't release memory when using Application.UnLoad()

    anyone else meet this issue?:(
     
    Last edited: May 31, 2021
  3. tinyant

    tinyant

    Joined:
    Aug 28, 2015
    Posts:
    117
    anyone meet this issue when Application.UnLoad() can't release memory?
     
  4. vagelis199

    vagelis199

    Joined:
    Jul 27, 2012
    Posts:
    116
    What you expect to be unloaded when you run this line of code? If you load a scene and never delete anything from the scene in runtime nothing would be unloaded.
     
  5. tinyant

    tinyant

    Joined:
    Aug 28, 2015
    Posts:
    117
    thanks for reply.

    like DOC says "On iOS and Android, Unload releases memory used by Scenes and GameObjects, but reserves some memory which is necessary for running Unity in the same process again."

    unload all scene content memory ,textures, audios and other engine resources load into game,Just reserves small memory for UnityEngine Core.

    https://docs.unity3d.com/ScriptReference/Application.Unload.html


    for example when I use unityengine as library for my APP, if my app game content about 500MB
    UnityEngine takes 120MB for engine core,

    if i call Appllication.Unload,Unity just keep about 120MB for engine core only, and will auto release other 380MB memory.

    I wonder if I misunderstand it's usages.
     
    Last edited: Jun 1, 2021
  6. vagelis199

    vagelis199

    Joined:
    Jul 27, 2012
    Posts:
    116
    You pretty much have nothing to unload here since everything you loaded is still active on the current scene you have loaded.
    Unless you Use GameObject.delete or something similar, then you can run ApplicationUnload to unload the nesesary textures and other data that the delete gameobject had in memory. and this will free up memory.
     
  7. tinyant

    tinyant

    Joined:
    Aug 28, 2015
    Posts:
    117

    I tried enter Clear Empty scene before call Application.Unload, All Textures memory was released,But still have extra memory used, Applcaiton.UnLoad should Auto release all content memory and just use small memory for keeping engine alive.
     
    vagelis199 likes this.
unityunity