I am creating WebGLof the unity project and loading the project from html file using UnityLoader.instantiate(). Our game requires more than 1.5 GB space to run so when the game is not running this instance occupying all memory.
I want to destroy the gameInstance created and free memory from browser completely. So for all forums and post suggest to embed the application or to reload the page.
Is it possible to do so from a script without using Embed or Page reload?
Is it possible to have api call to destroy or despose unity instance from the browser memory?
Something like : UnityLoader.dispose(gameInstance)
anastrophe : Here is the answer from the Unity Support might help you.
Goal: I want to destroy the gameInstance created and free memory from browser completely.
Question: Does unity provide any functionality to destroy gameInstance created? example : UnityLoader.dispose( gameInstance )
Answer: No, Unity doesn’t provide any method or functionality to achieve this. Also, there is no way to release memory explicitly in JavaScript, it will be garbage-collected by the GC any moment, but we can’t control when this occurs.
Question: Is there any other way I can destroy Unity game instance completely from Unity engine side.
Answer:
Sadly, the answer is no again. You could do:
gameInstance = null;
delete gameInstance;
But the memory won’t be released anyway because of the way of JavaScript works. Even, if you try injecting a DOM element with the canvas object and remove it when needed, the memory won’t be released. And also, using this approach, you would have to disable a lot of callbacks/listeners and free a lot of arrays, etc. And after that, you would have to create everything by hand again.
Note: Following options are tried and are not suiting to our needs.
a. Enclosing Unity instance in iFrame
b. Reloading Page / Opening another page.
Why didn’t the approach iFrame + reloading (the iFrame only) work for you?
(FWIW my problem with the iFrame and the reloading page option is that I’m building a progressive web app [PWA] and that’s not part of the approach/UX)
Hi guys,
its 2019 Feb, do there any new solution available to unload the application in webGL and free the memory?
If i understand this thread correctly, then there is no way avaialbe as we don’t have control over javascript GC?
Additionally if we use iframe to embed our application and then remove iframe then it will correctly and this is only the way.
Thank you very much i found this line here: “WebGL: Add Quit() function support to the unity instance”
Hopefully it is same that i am looking for but unity 2019 is still beta format. Although i will check it. If someone have more information about it then please let us know.