• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
5
Question by realragnvaldr · Apr 18, 2021 at 07:48 PM · errorerror messagedebugmemory leakstacktrace

Need help on "A Native Collection has not been disposed, resulting in a memory leak"

I've been working on an app for quite a while and never got this error until last week or so (after updating to 2021.1.2f1?) - and now it comes up all the time :-/

I don't know if this is related, but also since around last week, the contents of any vertical layout group in my app now sometimes suddenly becomes invisible or wiped. This happens only occasionally and so far only on the Android and iOS builds, not when running the app in the editor, which makes it tricky to debug.

After finally figuring out how to enable full stacktrace, I got a bit stuck on how to use the trace information (see below) to solve the problem. The information doesn't contain a reference to any code that i wrote myself, so I really don't know what to do with this. Any pointers on how to continue would be appreciated.

Thanks!

> 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[])
> UnityEngine.Networking.UnityWebRequest:SetupPost(UnityWebRequest, WWWForm)
> UnityEngine.Networking.UnityWebRequest:Post(String, WWWForm)
> 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 /Users/chkuang/Workspace/Git/unity-jar-resolver/source/VersionHandlerImpl/src/PortableWebRequest.cs:481)
> Google.c_AnonStorey6:<>mC() (at /Users/chkuang/Workspace/Git/unity-jar-resolver/source/VersionHandlerImpl/src/PortableWebRequest.cs:443)
> Google.RunOnMainThread:ExecuteNext() (at /Users/chkuang/Workspace/Git/unity-jar-resolver/source/VersionHandlerImpl/src/RunOnMainThread.cs:486)
> Google.RunOnMainThread:m
_12() (at /Users/chkuang/Workspace/Git/unity-jar-resolver/source/VersionHandlerImpl/src/RunOnMainThread.cs:536)
> Google.RunOnMainThread:RunAction(Action) (at /Users/chkuang/Workspace/Git/unity-jar-resolver/source/VersionHandlerImpl/src/RunOnMainThread.cs:343)
> Google.RunOnMainThread:ExecuteAllUnnested(Boolean) (at /Users/chkuang/Workspace/Git/unity-jar-resolver/source/VersionHandlerImpl/src/RunOnMainThread.cs:530)
> Google.RunOnMainThread:ExecuteAll() (at /Users/chkuang/Workspace/Git/unity-jar-resolver/source/VersionHandlerImpl/src/RunOnMainThread.cs:512)
> UnityEditor.EditorApplication:Internal_CallUpdateFunctions()

Comment
Add comment
10 |3000 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

10 Replies

· Add your reply
  • Sort: 
avatar image
5
Best Answer

Answer by stream_in_space_ · May 13, 2021 at 02:28 PM

It easy to fix. Just put your web request to a using construction. https://docs.unity3d.com/2021.2/Documentation/ScriptReference/Networking.UnityWebRequest.Dispose.html

Comment
Add comment · Show 3 · Share
10 |3000 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 realragnvaldr · May 14, 2021 at 09:15 PM 0
Share

Thanks! I have a lot of unitywebrequests - is it important to put them all in this construction wrapper? (And if it is really important, i suggest that Unity does this automatically in 2021.2.X and onwards ^.^)

avatar image stream_in_space_ realragnvaldr · May 17, 2021 at 11:07 AM 0
Share

If you want to avoid a memory leak it should be important )

avatar image Chethan007 · May 30, 2021 at 08:51 AM 0
Share

@stream_in_space_ Could you elaborate a lit more. Where do I find the web request. My game is crashing as soon as I launch it. Is it because of this issue? because I used admediation with unity and inMobi plugin and it works fine in unity, but when I used the updated version of that from play Store on my mobile it is crashing as soon as I launch

avatar image
3

Answer by carsonherrick · Apr 23, 2021 at 02:11 AM

Still occurring in 2021.1.4f1

Comment
Add comment · Share
10 |3000 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
0

Answer by Yumby · Apr 23, 2021 at 11:27 PM

We are seeing this in 2021.1.3f1 as well.

I have been trying to fix this same issue in our code but have only been partially successful. I’m now calling Dispose explicitly on the UploadHandler after the UnityWebRequest response has been returned but it still intermittently (but not always) reports this leak.

I did not have to call Dispose in 2019 or 2020 and according to the docs, UploadHandler Dispose should be called be default when the UnityWebRequest is disposed.

This appears to be a race condition or logic bug of some kind in the Unity platform code. Is there source code available to review for any of these classes?

Comment
Add comment · Share
10 |3000 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
0

Answer by DrJBN · May 26, 2021 at 12:52 PM

2021.1.7f1 too-

Comment
Add comment · Share
10 |3000 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
0

Answer by Chethan007 · May 30, 2021 at 08:45 AM

Yeah Even I am facing the same issue in 2021.1.7f1 personal edition too. what is the solution? My game is crashing in the beginning only

Comment
Add comment · Share
10 |3000 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
  • 1
  • 2
  • ›

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.

Follow this Question

Answers Answers and Comments

212 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

error CS0201 (2d roguelike) 1 Answer

how to fix WireframeBehaviour.cs(41,24): warning CS0618 error 0 Answers

CommandInvokationFailure: Failed to re-package resources. APK build error.! 1 Answer

Whenever I try to enter playmode after creating a script, a compiler error pops up 0 Answers

i d like do know how to resolve this error 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges