- Home /
AR Foundation adding reference images at runtime causes memory leak on iOS, but works fine on Android.
I want to add 500 reference images at runtime, for now I'm adding up to 250. This goes well on android, but not for iOS. Memory usage goes up to 1.6 GB until the app crashes.
Standard memory usage for my app is around 300 MB with lots of dynamic image thumbnails (approx. count 300) and other stuff.
After adding 250 reference images, runtime memory usage goes up to around 0.55GB on Android, but for the same scenario it goes up to 1.6GB on iOS.
Unity version: 2021.1.19f1
AR Foundation: 4.2.2
Android: Motorola One Fusion+ (Android 11, 6GB)
iPhone: iPhone XR (iOS 15.0.2, 3GB)
I'm adding the code snippet below, any help will be appreciated, thanks in advance.
private void Start()
{
//Other codes...
StartCoroutine(AddToLibrary(mutableLibrary, true));
}
private IEnumerator AddToLibrary(MutableRuntimeReferenceImageLibrary mutableLibrary, bool wait)
{
foreach (var item in markers)
{
using (UnityWebRequest unityWebRequest = UnityWebRequestTexture.GetTexture(item.Value))
{
yield return unityWebRequest.SendWebRequest();
if (unityWebRequest.result != UnityWebRequest.Result.Success)
{
Debug.LogError(unityWebRequest.error);
}
else
{
Texture2D texture2D = DownloadHandlerTexture.GetContent(unityWebRequest);
if (texture2D && imageManager && mutableLibrary != null)
{
var jobState = mutableLibrary.ScheduleAddImageWithValidationJob(texture2D, item.Key, 1);
yield return new WaitWhile(() => wait && !jobState.jobHandle.IsCompleted); //Optional wait
Destroy(texture2D);
}
}
}
yield return new WaitForEndOfFrame();
}
}
Your answer
Follow this Question
Related Questions
Object tracking with AR foundation not working 0 Answers
Creating a MemoryStream from WWW.bytes leaks memory 1 Answer
ARKit vs ARCore vs Vuforia vs 8th Wall 4 Answers
"Real Memory" usage in iOS expands the more often one prefab is referenced in the assetbundle 0 Answers
Face Tracking using openCV is not working accurately 0 Answers