unity-jar-resolver
unity-jar-resolver copied to clipboard
[Bug] PortableWebRequest appears to not Dispose() of generated UnityWebRequests
[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!
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!
Seeing this as well. Any ETA on a fix?
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>