question

Anthony Demanuele avatar image
Anthony Demanuele asked

PlayFabClientAPI.GetTime() causing memory leak on iOS

We've been struggling with an out of memory exception on iOS for the last few days and finally narrowed down the bug to this Playfab API call.


private IEnumerator<float> GetServerTime_Coroutine()
    {
        while (true)
        {
            GetTimeRequest getTimeRequest = new GetTimeRequest();
            PlayFabClientAPI.GetTime(getTimeRequest,
                (result) =>
                {
                    CurrentEasternServerTime = result.Time.AddHours(-4);
                },
                (error) =>
                {
                    Debug.LogErrorFormat("Failed getting server time. Error: {0}", error.GenerateErrorReport());
                }
            );
            yield return Timing.WaitForSeconds(60);
        }
    }

The function has been working fine for many months now but for some reason, the app goes from using around 400Mb upwards until it crashes. If we comment out the GetTime() call, the memory leak does not happen anymore. We tried this on SDK versions 2.107.210427 and 2.109.210521 as well.

Is anyone else encountering this or has ideas how to fix it?

Thank you!

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
Anthony Demanuele avatar image
Anthony Demanuele answered

In addition, this API function is causing this error every now and then (only started a few weeks ago) so this to us means something changed in the backend.

Failed getting server time. Error: /Client/GetTime: Unhandled error in PlayFabUnityHttp: System.IndexOutOfRangeException: Index was outside the bounds of the array. at PlayFab.Internal.PlayFabUnityHttp+<Post>d__12.MoveNext () [0x00152] in

For the time being, we replaced this call to a cloudscript function and the memory leak is gone.

handlers.GetServerTime = function(args) 
{
	var now = new Date();
	return now.getTime();
}
3 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Sarah Zhang avatar image Sarah Zhang commented ·

We can’t reproduce the memory exception using the code. The test environment is Unity 2019.4.21f1 and PlayFab SDK 2.109.210521. Does this issue still exist? If it does, could you please provide more details about the issue? For example, After how many times the GetTime() be called, the application would crash? And how you defined the Timing that used in the “yield return Timing.WaitForSeconds(60);”?

0 Likes 0 ·
Anthony Demanuele avatar image Anthony Demanuele Sarah Zhang commented ·

Thanks for your testing Sarah.

We are using the following:

1. Unity 2020.3.2f1

2. Timing is a plugin which creates less GC when compared to Unitys coroutines - you can find it here: More Effective Coroutines [FREE] | Animation Tools | Unity Asset Store

3. Tested on iPhone 6, iPhone X (iOS 14.6) and iPhone 12

4. Happens after calling GetTime() 2 or times at an interval of 60 seconds each.

(So app crashes in under 5 minutes)


Hope this helps

0 Likes 0 ·
Sarah Zhang avatar image Sarah Zhang Anthony Demanuele commented ·

Thanks so much for your information. Did this program crash on iPhone 6, iPhone X, and iPhone all within the same time? Do these devices own the same size of the memory?

0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.