Hello folks,
This has bother me for a while. Basically, if we want to create two scenes in Unity, first scene is just a dummy one with a button, while the second scene is a basic cloud recognition scene built from Unity Vuforia extension, then try to use buttons to switch between these two. Then each time when getting out from Vuforia scene there will be about 10 MB memory increase. I put the load scene script on the camera (in Vuforia scene, the script is attached to ARCamera).
The content of the load scene is as below:
using UnityEngine; using System.Collections; using UnityEngine.SceneManagement; public class LoadLevel : MonoBehaviour { public string levelName; // Use this for initialization void Start () { } // Update is called once per frame void Update () { } public void loadLevel() { if (levelName != null) { DestroyAllGameObjects (); SceneManager.LoadScene (levelName); } } public void DestroyAllGameObjects() { GameObject[] GameObjects = (FindObjectsOfType<GameObject>() as GameObject[]); for (int i = 0; i < GameObjects.Length; i++) { Destroy(GameObjects[i]); } } }
Then we built the two scene to iOS project, where the dummy scene is the default one. After running in XCode we notice the pattern of the memory increase. We also notice that the log output:
Vuforia.TrackableBehaviour:OnDisable()
LoadLevel:DestroyAllGameObjects()
LoadLevel:loadLevel()
UnityEngine.Events.InvokableCallList:Invoke(Object[])
UnityEngine.EventSystems.ExecuteEvents:Execute(GameObject, BaseEventData, EventFunction`1)
UnityEngine.EventSystems.StandaloneInputModule:ProcessTouchPress(PointerEventData, Boolean, Boolean)
UnityEngine.EventSystems.StandaloneInputModule:ProcessTouchEvents()
UnityEngine.EventSystems.StandaloneInputModule:Process()
(Filename: /Users/builduser/buildslave/unity/build/artifacts/generated/common/runtime/UnityEngineDebugBindings.gen.cpp Line: 37)
targetFinderStop
StopVuforia
Vuforia.VuforiaAbstractBehaviour:StopVuforia()
Vuforia.VuforiaAbstractBehaviour:OnDisable()
LoadLevel:DestroyAllGameObjects()
LoadLevel:loadLevel()
UnityEngine.Events.InvokableCallList:Invoke(Object[])
UnityEngine.EventSystems.ExecuteEvents:Execute(GameObject, BaseEventData, EventFunction`1)
UnityEngine.EventSystems.StandaloneInputModule:ProcessTouchPress(PointerEventData, Boolean, Boolean)
UnityEngine.EventSystems.StandaloneInputModule:ProcessTouchEvents()
UnityEngine.EventSystems.StandaloneInputModule:Process()
(Filename: /Users/builduser/buildslave/unity/build/artifacts/generated/common/runtime/UnityEngineDebugBindings.gen.cpp Line: 37)
trackerStop 8
trackerStop 7
cameraDeviceStopCamera
cameraDeviceDeinitCamera
targetFinderDeinit
trackerStop 7
trackerStop 8
trackerManagerDeinitTracker
trackerManagerDeinitTracker
Unloading 2 Unused Serialized files (Serialized files now loaded: 0)
UnloadTime: 1.863750 ms
Unloading 13 unused Assets to reduce memory usage. Loaded Objects now: 312.
Total: 4.061583 ms (FindLiveObjects: 0.067416 ms CreateObjectMapping: 0.087041 ms MarkObjects: 1.802250 ms DeleteObjects: 2.103541 ms)
We can see the red line. 312 objects are kept even when we have switched back to the dummy scene which only have a main camera, a light, and a UI button. So now if I keep click this button to go to the Vuforia scene and get back there, the memory keeps increasing.
Here is a instrument screen shot shows the leaked pattern as the attached image
Hope there is some experience to be shared here about this issue. We do hope that we can keep this "scene switch" in our project but if you don't think this is possible please also let me know.
Thank you!
Attachment | Size |
---|---|
![]() | 196.99 KB |
Hello,
This issue was resolved in Vuforia 6.
Thanks.