Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] PortableWebRequest appears to not Dispose() of generated UnityWebRequests #473

Open
jmcguirk opened this issue Oct 21, 2021 · 3 comments

Comments

@jmcguirk
Copy link

jmcguirk commented Oct 21, 2021

[READ] For Firebase Unity SDK issues, please report to Firebase Unity Sample

Once you've read this section and determined that your issue is appropriate for this repository, please delete this section.

[REQUIRED] Please fill in the following fields:

  • Unity editor version: 2021.1.9f1
  • External Dependency Manager version: 1.2.162
  • Source you installed EDM4U: .unitypackage
  • Features in External Dependency Manager in use: Android Resolver, iOS Resolver, VersionHandler
  • Plugins SDK in use: Firebase, Admob, Facebook, IronSrc
  • Platform you are using the Unity editor on: Mac

[REQUIRED] Please describe the issue here:

(Please list the full steps to reproduce the issue. Include device logs, Unity logs, and stack traces if available.)

  • Create a new project in Unity 2021.1.9f1
  • Install the Entities package (Package Manager -> + -> Add Package By Name.. -> com.unity.entities) - This is ONLY necessary to view the stack traces of the underlying allocations
  • Enable stack traces by going to Jobs -> Leak Detection -> Full Stack Traces (expensive)
  • Run the game, then stop the game

Observe the following error logs are printed in the console

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)
UnityEngine.Networking.UnityWebRequest:SetupPost(UnityWebRequest, WWWForm) (at /Users/bokken/buildslave/unity/build/Modules/UnityWebRequest/Public/WebRequestExtensions.cs:206)
UnityEngine.Networking.UnityWebRequest:Post(String, WWWForm) (at /Users/bokken/buildslave/unity/build/Modules/UnityWebRequest/Public/WebRequestExtensions.cs:184)
System.Reflection.MonoMethod:InternalInvoke(Object, Object[], Exception&)
System.Reflection.MonoMethod:Invoke(Object, BindingFlags, Binder, Object[], CultureInfo)
System.Reflection.MethodBase:Invoke(Object, Object[])
Google.PortableWebRequest:StartRequest(HttpMethod, String, IDictionary`2, WWWForm) (at Z:\tmp\tmp.8iabTPBNjq\third_party\unity\unity_jar_resolver\source\VersionHandlerImpl\src\PortableWebRequest.cs:481)
Google.<StartRequestOnMainThread>c__AnonStorey0:<>m__0() (at Z:\tmp\tmp.8iabTPBNjq\third_party\unity\unity_jar_resolver\source\VersionHandlerImpl\src\PortableWebRequest.cs:443)
Google.RunOnMainThread:ExecuteNext() (at Z:\tmp\tmp.8iabTPBNjq\third_party\unity\unity_jar_resolver\source\VersionHandlerImpl\src\RunOnMainThread.cs:486)
Google.RunOnMainThread:<ExecuteAllUnnested>m__1() (at Z:\tmp\tmp.8iabTPBNjq\third_party\unity\unity_jar_resolver\source\VersionHandlerImpl\src\RunOnMainThread.cs:536)
Google.RunOnMainThread:RunAction(Action) (at Z:\tmp\tmp.8iabTPBNjq\third_party\unity\unity_jar_resolver\source\VersionHandlerImpl\src\RunOnMainThread.cs:343)
Google.RunOnMainThread:ExecuteAllUnnested(Boolean) (at Z:\tmp\tmp.8iabTPBNjq\third_party\unity\unity_jar_resolver\source\VersionHandlerImpl\src\RunOnMainThread.cs:530)
Google.RunOnMainThread:ExecuteAll() (at Z:\tmp\tmp.8iabTPBNjq\third_party\unity\unity_jar_resolver\source\VersionHandlerImpl\src\RunOnMainThread.cs:512)
UnityEditor.EditorApplication:Internal_CallUpdateFunctions() (at /Users/bokken/buildslave/unity/build/Editor/Mono/EditorApplication.cs:327)

Please answer the following, if applicable:

What's the issue repro rate? (eg 100%, 1/5 etc)

100%

What happened? How can we make the problem occur?
This could be a description, log/console output, etc.

Unity warns that an underlying native struct (i.e. an array) was allocated and never disposed. The stack trace indicates the origin of this allocation is from PortableWebRequest in VersionHandlerImpl. In reviewing the code, this appears to be the case - no where are the requests generated in PortableWebRequest .Disposed()

My own code base actually had similar issues, and it was a failure to reliably call Dispose() on the underlying UnityWebRequest that is used.

These are likely small allocations made in Editor only, so the priority is probably fairly low - however, as more developers adopt their existing projects to 2021+, they will want to see the instances of these leaks hit zero and it'd be good if EDM wasn't showing up here.

Cheers!

@jmcguirk jmcguirk added new to be triaged type: question labels Oct 21, 2021
@chkuang-g chkuang-g added type: bug and removed type: question new to be triaged labels Oct 25, 2021
@chkuang-g
Copy link
Collaborator

Ah, this looks like a legit issue and oversight.
https://docs.unity3d.com/ScriptReference/Networking.UnityWebRequest.Dispose.html

If this is causing OOM issue for you, I recommend to turn off editor analytics feature which you can find under
Assets > External Dependency Manager > Version Handler > Settings menu item. I think this is the only feature that is using PortableWebRequest.

Thank you for reporting this!

@chornesays
Copy link

Seeing this as well. Any ETA on a fix?

@gvuyk
Copy link

gvuyk commented Jul 27, 2023

Hit this recently too, manually calling UnityWebRequest's dispose method didn't solve it.
What did solve it was replacing the old WWWForm with a Dictionary<string, string>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants