Topic locked

Memory leak if use LoadScene in Unity for iOS

June 23, 2016 - 8:24pm #1

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!

Memory leak if use LoadScene in Unity for iOS

August 9, 2016 - 3:39pm #10

Hello,

This issue was resolved in Vuforia 6.

Thanks.

Memory leak if use LoadScene in Unity for iOS

July 11, 2016 - 4:01pm #9

Hello,

I've escalated with the team for confirmation that this will be resolved in our next commercial release.

Thanks for the patience.

Memory leak if use LoadScene in Unity for iOS

July 11, 2016 - 10:43am #8

Good morning Medabit!

 

Hope you are doing well! JUst come back to check the status of this issue. Thank you.

 

Sincerely,

Will

Memory leak if use LoadScene in Unity for iOS

June 29, 2016 - 8:14am #7

Hello,

Apologies, but I do not have an ETA on a fix. Our team is actively investigating the issue. I will continue to track the issue and provide relevant updates, if any are available. Feel free to ping me again next week for a status update.

Thanks

Memory leak if use LoadScene in Unity for iOS

June 29, 2016 - 7:47am #6

Any kind of ETA on this, I have an AR installation in a museum that needs a fix desperately.

Memory leak if use LoadScene in Unity for iOS

June 24, 2016 - 2:40pm #5

Hello,

Thank you again for your report, and apologies for the delay in the investigation. We were able to reproduce the issue and have initiated a ticket with core engineering to investigate. At this time I do not have an ETA as to when it may be resolved, but will do my best to provide relevant updates to this thread as they become available.

On a side note, we thank you for raising the issue and providing the evidence and steps required to reproduce. We appreciate your contributions to making our product the best it can be.

Cheers!

Memory leak if use LoadScene in Unity for iOS

June 24, 2016 - 10:13am #4

https://developer.vuforia.com/forum/unity-extension-technical-discussion/ar-crashes-after-returning-another-scene

---------------

Thanks for looking into it!

 

I have tried the following today.

CameraDevice.Instance.Stop();
CameraDevice.Instance.Deinit();

VuforiaManager.Instance.Deinit();

VuforiaRuntimeUtilities.ForceDisableTrackables();

VideoBackgroundManager.Instance.SetVideoBackgroundEnabled(false);

System.GC.Collect();

Resources.UnloadUnusedAssets();

 

-----------------------

if I use VuforiaUnity.Deinit() I get all the memory back but cant load vuforia again.

 

All help is appreciated!

Best regards,

Stephan

 

Memory leak if use LoadScene in Unity for iOS

June 24, 2016 - 8:15am #3

Hello,

Would it be possible for you to provide the link to your original forum post? This would be helpful to us to better understand the history of this issue as we look further into your report.

Thanks

 

Memory leak if use LoadScene in Unity for iOS

June 24, 2016 - 5:21am #2

This has been an issue for me for almost 1 year, I noticed it November 2015 and reported it in the forum.  Never got a helpful response from Vuforia, its a pretty serious issue.  I think its actually gotten worse, it use to be 2-3 megs.  I am working on upgrading an old project now and can confirm its 10 megs when you unload a scene with vuforia in it.  Does not matter if you do garbage collect or resource unload.  Also does not make a difference if you use the scene manager or application.loadlevel.  My guess is they are sloppy with assigning a bunch of listeners and don't automatically remove them in the trackable object, hopefully its not in the plugin and can be manually addressed in Unity.  I will let you know if I figure anything out. 

Unity 5.3.5

Vuforia 5-5-9

 

Best regards

Stephan

Topic locked