2023年1月16日月曜日

PlayFabで”A Native Collection has not been disposed, resulting in a memory leak.”というエラーが出たときの対処方法

 PlayFab”A Native Collection has not been disposed, resulting in a memory leak.”というエラーが出たときの対処方法


PlayFabを使っていて、”A Native Collection has not been disposed, resulting in a memory leak. Allocated from:

Unity.Collections.NativeArray`1:.ctor(Byte[], Allocator) (at /Users/bokken/build/output/unity/unity/Runtime/Export/NativeArray/NativeArray.cs:69)”

というエラーが出ることがあります。

NativeArray.cs69行目でエラーが起きていて、メモリリークしているようです。



A Native Collection has not been disposed, resulting in a memory leak. Allocated from:

Unity.Collections.NativeArray`1:.ctor(Byte[], Allocator) (at /Users/bokken/build/output/unity/unity/Runtime/Export/NativeArray/NativeArray.cs:69)

UnityEngine.Networking.UploadHandlerRaw:.ctor(Byte[]) (at /Users/bokken/build/output/unity/unity/Modules/UnityWebRequest/Public/UploadHandler/UploadHandler.bindings.cs:95)

PlayFab.Internal.<Post>d__12:MoveNext() (at Assets/PlayFabSDK/Shared/Internal/PlayFabHttp/PlayFabUnityHttp.cs:117)

UnityEngine.SetupCoroutine:InvokeMoveNext(IEnumerator, IntPtr) (at /Users/bokken/build/output/unity/unity/Runtime/Export/Scripting/Coroutines.cs:17)

UnityEngine.MonoBehaviour:StartCoroutineManaged2(MonoBehaviour, IEnumerator)

UnityEngine.MonoBehaviour:StartCoroutine(IEnumerator) (at /Users/bokken/build/output/unity/unity/Runtime/Export/Scripting/MonoBehaviour.bindings.cs:91)

PlayFab.Internal.PlayFabUnityHttp:MakeApiCall(Object) (at Assets/PlayFabSDK/Shared/Internal/PlayFabHttp/PlayFabUnityHttp.cs:107)

PlayFab.Internal.PlayFabHttp:_MakeApiCall(String, String, PlayFabRequestCommon, AuthType, Action`1, Action`1, Object, Dictionary`2, Boolean, PlayFabAuthenticationContext, PlayFabApiSettings, IPlayFabInstanceApi) (at Assets/PlayFabSDK/Shared/Internal/PlayFabHttp/PlayFabHTTP.cs:228)

PlayFab.Internal.PlayFabHttp:MakeApiCall(String, PlayFabRequestCommon, AuthType, Action`1, Action`1, Object, Dictionary`2, PlayFabAuthenticationContext, PlayFabApiSettings, IPlayFabInstanceApi) (at Assets/PlayFabSDK/Shared/Internal/PlayFabHttp/PlayFabHTTP.cs:133)

PlayFab.PlayFabEventsInstanceAPI:WriteEvents(WriteEventsRequest, Action`1, Action`1, Object, Dictionary`2) (at Assets/PlayFabSDK/Events/PlayFabEventsInstanceAPI.cs:63)

PlayFab.Public.ScreenTimeTracker:Send() (at Assets/PlayFabSDK/Entity/ScreenTimeTracker.cs:190)

PlayFab.Public.ScreenTimeTracker:OnApplicationFocus(Boolean) (at Assets/PlayFabSDK/Entity/ScreenTimeTracker.cs:165)

PlayFab.Internal.PlayFabHttp:OnApplicationFocus(Boolean) (at Assets/PlayFabSDK/Shared/Internal/PlayFabHttp/PlayFabHTTP.cs:334)

UnityEditorInternal.InternalEditorUtility:OnGameViewFocus(Boolean)

UnityEditor.PlayModeView:SetFocus(Boolean) (at /Users/bokken/build/output/unity/unity/Editor/Mono/PlayModeView/PlayModeView.cs:441)

UnityEditor.GameView:OnLostFocus() (at /Users/bokken/build/output/unity/unity/Editor/Mono/GameView/GameView.cs:385)

UnityEditor.HostView:OnLostFocus() (at /Users/bokken/build/output/unity/unity/Editor/Mono/HostView.cs:295)



色々と調べていると、こちらに記事がありました。


PlayFabSdk/Shared/Public/Resources にある “PlayFabSharedSettings.asset “というファイルを、Assets/Resources にコピーすると直りました。