Microsoft Azure PlayFab logo
    • Multiplayer
    • LiveOps
    • Data & Analytics
    • Add-ons
    • For Any Role

      • Engineer
      • Designer
      • Executive
      • Marketer
    • For Any Stage

      • Build
      • Improve
      • Grow
    • For Any Size

      • Solo
      • Indie
      • AAA
  • Runs on PlayFab
  • Pricing
    • Blog
    • Forums
    • Contact us
  • Sign up
  • Sign in
  • Ask a question
  • Spaces
    • PlayStream
    • Feature Requests
    • Add-on Marketplace
    • Bugs
    • API and SDK Questions
    • General Discussion
    • LiveOps
    • Topics
    • Questions
    • Articles
    • Ideas
    • Users
    • Badges
  • Home /
  • Bugs /
avatar image
Question by Richard Berger · Apr 28, 2021 at 01:25 AM · unity3d

I'm getting the following error in PlayFab in Unity. Does anyone have any idea how to fix it? It's beyond me.

Comment

People who like this

0 Show 1
10 |1200 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Richard Berger · Apr 27, 2021 at 07:52 PM 0
Share

Here's the error message:

A Native Collection has not been disposed, resulting in a memory leak. Enable Full StackTraces to get more details.

I get it on a regular basis, sometimes when the code is running, sometimes when I'm just in the editor. It doesn't seem to be breaking anything but I'd like to be able to fix it.

6 Replies

· Add your reply
  • Sort: 
avatar image

Answer by Ivan Cai · Apr 28, 2021 at 09:24 AM

This issue seems to belong to the business category of unity, not playfab. You need to navigate to [Jobs]->[Leak Detection]->[Full Stack Traces], select it and restart unity.Then the error content in the console will be show that the memory leak occurred in the data retention location. After knowing the location of the leak, you just put the variable in Dispose, but it is recommended to enclose it in the using statement.

Comment

People who like this

0 Show 0 · Share
10 |1200 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image

Answer by Ralv Wohlgethan · May 10, 2021 at 01:25 AM

@Richard Berger You might need to actually include the jobs package (manually, maybe) in your manifest.json file:

"dependencies": {
  ...  
  "com.unity.jobs": "0.8.0-preview.23",
  ...
}

Depending on who reads this post and when, the actual package version may of course differ, but you should be able to update from the editor (PackageManager UI) after modifying your manifest.json (unless Unity decides to drop the package or integrate it elsewhere, of course, but then this answer will be outdated anyway...).

Comment

People who like this

0 Show 0 · Share
10 |1200 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image

Answer by Ralv Wohlgethan · May 10, 2021 at 01:25 AM

Actually (if it gets published) you can ignore my previous answer. While the number of memory leaks has seemingly decreased with the integration of the latest jobs package, they do still occur and seem to originate from the PlayFabUnityHttp class. At least this is what I'd conclude from the stacktrace:

A Native Collection has not been disposed, resulting in a memory leak. Allocated from:
Unity.Collections.NativeArray`1:.ctor(Byte[], Allocator) (at /Users/bokken/buildslave/unity/build/Runtime/Export/NativeArray/NativeArray.cs:69)
UnityEngine.Networking.UploadHandlerRaw:.ctor(Byte[]) (at /Users/bokken/buildslave/unity/build/Modules/UnityWebRequest/Public/UploadHandler/UploadHandler.bindings.cs:98)
PlayFab.Internal.<Post>d__12:MoveNext() (at Assets/PlayFabSDK/Shared/Internal/PlayFabHttp/PlayFabUnityHttp.cs:129)
UnityEngine.SetupCoroutine:InvokeMoveNext(IEnumerator, IntPtr) (at /Users/bokken/buildslave/unity/build/Runtime/Export/Scripting/Coroutines.cs:17)
UnityEngine.MonoBehaviour:StartCoroutineManaged2(IEnumerator)
UnityEngine.MonoBehaviour:StartCoroutine(IEnumerator) (at /Users/bokken/buildslave/unity/build/Runtime/Export/Scripting/MonoBehaviour.bindings.cs:91)
PlayFab.Internal.PlayFabUnityHttp:MakeApiCall(Object) (at Assets/PlayFabSDK/Shared/Internal/PlayFabHttp/PlayFabUnityHttp.cs:119)
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.PlayFabClientAPI:ReportDeviceInfo(DeviceInfoRequest, Action`1, Action`1, Object, Dictionary`2) (at Assets/PlayFabSDK/Client/PlayFabClientAPI.cs:1751)
PlayFab.Internal.PlayFabDeviceUtil:SendDeviceInfoToPlayFab(PlayFabApiSettings, IPlayFabInstanceApi) (at Assets/PlayFabSDK/Client/PlayFabDeviceUtil.cs:54)
PlayFab.Internal.PlayFabDeviceUtil:_OnPlayFabLogin(UserSettings, String, String, String, PlayFabApiSettings, IPlayFabInstanceApi) (at Assets/PlayFabSDK/Client/PlayFabDeviceUtil.cs:127)
PlayFab.Internal.PlayFabDeviceUtil:OnPlayFabLogin(PlayFabResultCommon, PlayFabApiSettings, IPlayFabInstanceApi) (at Assets/PlayFabSDK/Client/PlayFabDeviceUtil.cs:102)
PlayFab.Internal.PlayFabUnityHttp:OnResponse(String, CallRequestContainer) (at Assets/PlayFabSDK/Shared/Internal/PlayFabHttp/PlayFabUnityHttp.cs:234)
PlayFab.Internal.<Post>d__12:MoveNext() (at Assets/PlayFabSDK/Shared/Internal/PlayFabHttp/PlayFabUnityHttp.cs:198)
UnityEngine.SetupCoroutine:InvokeMoveNext(IEnumerator, IntPtr) (at /Users/bokken/buildslave/unity/build/Runtime/Export/Scripting/Coroutines.cs:17)

Don't mind the "/Users/bokken/..." paths, this is Unity's build machine, so no need to worry.

In our own implementations with UnityWebRequest we always use "using" blocks. This ensures that the request is always disposed of properly. I'm not sure why this isn't the case in PlayFabUnityHttp, but a first look seems to imply that it is indeed possible to create a memory leak when the manual call of

www.Dispose()

at the very end isn't reached... Interesting enough, the code contradicts @Ivan Cai's proposal of doing exactly this (using "using" blocks)...

Another error source seems to be in PlayFabEditorHttp:

A Native Collection has not been disposed, resulting in a memory leak. Allocated from:
Unity.Collections.NativeArray`1:.ctor(Byte[], Allocator) (at /Users/bokken/buildslave/unity/build/Runtime/Export/NativeArray/NativeArray.cs:69)
UnityEngine.Networking.UploadHandlerRaw:.ctor(Byte[]) (at /Users/bokken/buildslave/unity/build/Modules/UnityWebRequest/Public/UploadHandler/UploadHandler.bindings.cs:98)
PlayFab.PfEditor.PlayFabEditorHttp:MakeApiCall(String, String, GetStudiosRequest, Action`1, Action`1) (at Assets/PlayFabEditorExtensions/Editor/Scripts/PlayFabEditorSDK/PlayFabEditorHttp.cs:74)
PlayFab.PfEditor.PlayFabEditorApi:GetStudios(GetStudiosRequest, Action`1, Action`1) (at Assets/PlayFabEditorExtensions/Editor/Scripts/PlayFabEditorSDK/PlayFabEditorApi.cs:30)
PlayFab.PfEditor.PlayFabEditorDataService:RefreshStudiosList(Boolean) (at Assets/PlayFabEditorExtensions/Editor/Scripts/Utils/PlayFabEditorDataService.cs:198)
PlayFab.PfEditor.PlayFabEditor:OnEnable() (at Assets/PlayFabEditorExtensions/Editor/PlayFabEditor.cs:45)
PlayFab.PfEditor.PlayFabEditor:OnFocus() (at Assets/PlayFabEditorExtensions/Editor/PlayFabEditor.cs:62)
UnityEditor.HostView:RegisterSelectedPane(Boolean) (at /Users/bokken/buildslave/unity/build/Editor/Mono/HostView.cs:502)
UnityEditor.HostView:OnEnable() (at /Users/bokken/buildslave/unity/build/Editor/Mono/HostView.cs:154)
UnityEditor.DockArea:OnEnable() (at /Users/bokken/buildslave/unity/build/Editor/Mono/GUI/DockArea.cs:174)

In this case, at first glance, I can't find neither a using block nor any Dispose() call. Hope this helps...


Playfab SDK version: 2.107.210427(shown as latest release as of 2021-05-08)

Comment
Richard Berger

People who like this

1 Show 0 · Share
10 |1200 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image

Answer by Richard Berger · May 27, 2021 at 01:48 AM

Here's the stack trace that I did manage to then get - maybe this helps...

A Native Collection has not been disposed, resulting in a memory leak. Allocated from:
Unity.Collections.NativeArray`1:.ctor(Byte[], Allocator)
UnityEngine.Networking.UploadHandlerRaw:.ctor(Byte[])
PlayFab.Internal.<Post>d__12:MoveNext() (at Assets\PlayFabSDK\Shared\Internal\PlayFabHttp\PlayFabUnityHttp.cs:129)
UnityEngine.SetupCoroutine:InvokeMoveNext(IEnumerator, IntPtr)
UnityEngine.MonoBehaviour:StartCoroutineManaged2(IEnumerator)
UnityEngine.MonoBehaviour:StartCoroutine(IEnumerator)
PlayFab.Internal.PlayFabUnityHttp:MakeApiCall(Object) (at Assets\PlayFabSDK\Shared\Internal\PlayFabHttp\PlayFabUnityHttp.cs:119)
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:181)
PlayFab.Public.ScreenTimeTracker:OnApplicationFocus(Boolean) (at Assets\PlayFabSDK\Entity\ScreenTimeTracker.cs:156)
PlayFab.Internal.PlayFabHttp:OnApplicationFocus(Boolean) (at Assets\PlayFabSDK\Shared\Internal\PlayFabHttp\PlayFabHTTP.cs:332)
UnityEditorInternal.InternalEditorUtility:OnGameViewFocus(Boolean)
UnityEditor.PlayModeView:SetFocus(Boolean)
UnityEditor.GameView:OnLostFocus()
UnityEditor.HostView:OnLostFocus()
Comment
Ralv Wohlgethan

People who like this

1 Show 1 · Share
10 |1200 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image SethDu ♦ · Jun 24, 2021 at 09:15 AM 0
Share

Hi, we have noticed the memory leak issue in 2021 Unity Engine. However, to manually fix this issue, it may need plenty of work to put web request to a using construction, according to: Need help on "A Native Collection has not been disposed, resulting in a memory leak" - Unity Answers.

For now, you can switch to the LTS version of Unity to avoid this warning, otherwise, please wait for the updates of Unity or PlayFab Unity SDK.

avatar image

Answer by Chethan V · Jan 10 at 12:02 PM

I closed Unity,deleted the Library folder and restarted Unity. Unity automatically imported the necessary files and the error went away. Hope this helps someone

Comment

People who like this

0 Show 0 · Share
10 |1200 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image

Answer by CHO YOUNGMIN · Feb 11 at 02:16 AM

Actually it's easy to solve.

This is a PlayFabSharedSettings ' directory problem.

When you import Playfab SDK, basically PlayFabSharedSettings is exist in [PlayFabSDK] - [Shared] - [Public] - [Resources].

But take a look the PlayFabSettings.GetSharedSettingsObjectPrivate() .

It load all PlayFabSharedSettings from "Resources" like :

var settingsList = Resources.LoadAll<PlayFabSharedSettings>("PlayFabSharedSettings");

return settingsList[0];.

So basically as all we know, Resources. ~~ access to [Asset] - [Resources].

Not [PlayFabSDK] - [Shared] - [Public] - [Resources].

So go [PlayFabSDK] - [Shared] - [Public] - [Resources], Copy PlayFabSharedSettings,

Paste to [Asset] - [Resources]. then it will works.

Comment
toddhd

People who like this

1 Show 1 · Share
10 |1200 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image toddhd · Jun 21 at 10:50 PM 0
Share

Thank you for this. This fixed the problem for me and only took a moment to do.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Navigation

Spaces
  • General Discussion
  • API and SDK Questions
  • Feature Requests
  • PlayStream
  • Bugs
  • Add-on Marketplace
  • LiveOps
  • Follow this Question

    Answers Answers and Comments

    5 People are following this question.

    avatar image avatar image avatar image avatar image avatar image

    Related Questions

    Unity Android Plugin 1 Answer

    Can't Install PlayFab Unity SDK. 1 Answer

    Just updated to Unity version 2021.1.18f1, how do you resolve the error with Playfab GSDK "The type or namespace name 'MultiplayerAgentAPI' does not exist in the namespace 'PlayFab'" 1 Answer

    Unity Editor Extension does not appear 0 Answers

    Unity SDK il2cpp compilation issue 2 Answers

    PlayFab

    • Multiplayer
    • LiveOps
    • Data & Analytics
    • Runs on PlayFab
    • Pricing

    Solutions

    • For Any Role

      • Engineer
      • Designer
      • Executive
      • Marketer
    • For Any Stage

      • Build
      • Improve
      • Grow
    • For Any Size

      • Solo
      • Indie
      • AAA

    Engineers

    • Documentation
    • Quickstarts
    • API Reference
    • SDKs
    • Usage Limits

    Resources

    • Forums
    • Contact us
    • Blog
    • Service Health
    • Terms of Service
    • Attribution

    Follow us

    • Facebook
    • Twitter
    • LinkedIn
    • YouTube
    • Sitemap
    • Contact Microsoft
    • Privacy & cookies
    • Terms of use
    • Trademarks
    • Safety & eco
    • About our ads
    • © Microsoft 2020
    • Anonymous
    • Sign in
    • Create
    • Ask a question
    • Create an article
    • Post an idea
    • Spaces
    • PlayStream
    • Feature Requests
    • Add-on Marketplace
    • Bugs
    • API and SDK Questions
    • General Discussion
    • LiveOps
    • Explore
    • Topics
    • Questions
    • Articles
    • Ideas
    • Users
    • Badges