- Home /
Leaking GFX memory on iOS on LoadSceneAsync
I use following scenario to implement loading screen between scenes in one of my games:
I have a separate scene which displays loading animation and loads target scene asynchronously. Scene consists of animation GUI and SceneTransition class implementing target scene loading logic
Whenever I want to load new scene with loading screen, I call static method SceneTransition.GoToScene(string sceneName) Loading screen scene is loaded and async loading of target scene starts
When target scene loads, profiler reports increase in allocated GFX memory (this seem to depend on a scene complexity, in case of my game it's around 20 additional MB). This memory is never released which, in case of my game, leads to crash after switching scenes ~15 times.
I've managed to make a simplified example, which has a scene with RELOAD button and loading screen scene. Clicking on RELOAD button causes loading the same scene asynchronously while displaying loading screen. In this case there is consistent increase of about 1MB in GFX on iPhone 5 device.
This happens in iOS build, but not in editor. Is it a Unity bug, or am I making some mistake with loading script?
using UnityEngine;
using UnityEngine.SceneManagement;
using System.Collections;
using UnityEngine.UI;
public class SceneTransition : MonoBehaviour {
private static string sceneToLoad = "";
public Text m_loadingText;
void Start () {
var loadingTask = SceneManager.LoadSceneAsync(sceneToLoad, LoadSceneMode.Single);
StartCoroutine(LoadingAnimation(loadingTask));
}
public static void GoToScene(string scene)
{
sceneToLoad = scene;
SceneManager.LoadScene("LoadingScene", LoadSceneMode.Single);
}
IEnumerator LoadingAnimation(AsyncOperation loadingTask)
{
while (!loadingTask.isDone)
{
int progressPercent = (int)(loadingTask.progress * 100);
m_loadingText.text = "Loading " + progressPercent.ToString() + "%";
yield return null;
}
}
}
Link to project reproducing this issue: http://bit.ly/1SMFDBz
Did you ever manage to find a solution to this? I seem to having the same issue in a game I'm working on.
maybe unloading assets manually from memory would fix it???
try after scene loaded :
Resources.UnloadUnusedAssets();
Your answer
Follow this Question
Related Questions
Issue with object not bouncing around screen correctly 1 Answer
Why on the mobile do the elements seem to have a very unstable position? 0 Answers
Is it possible to cache next level before loading it with LoadLevelAsync()? 1 Answer
Animated Loading Screen Unity Indie 0 Answers
WebGL Loading Bar 0 Answers