Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Join us on Dec 8, 2022, between 7 am & 7 pm EST, in the DOTS Dev Blitz Day 2022 - Q&A forum, Discord, and Unity3D Subreddit to learn more about DOTS directly from the Unity Developers.
    Dismiss Notice
  3. Have a look at our Games Focus blog post series which will show what Unity is doing for all game developers – now, next year, and in the future.
    Dismiss Notice

Question Memory leak unity 2021

Discussion in 'Scripting' started by mrm83, Sep 14, 2022.

  1. mrm83

    mrm83

    Joined:
    Nov 29, 2014
    Posts:
    324
    Unity20213.9f

    Have been experiencing memory leak since using unity 2021. I just tried using the memory profiler and noticed that within 4 minutes, memory allocated grew 10GB (editor). I am not even doing anything in the scene, and the scene doesn't even do anything other then the fact that it does a webquest, show some buttons, and thats it.

    Comparing the snapshots, I was able to see that these allocations all came from Managed Array System.Byte[]. There are hundreds (maybe even 1000+) of these System.Byte[] ranging from 0-100827136 in lengths.

    Now.. How can I see where these byte[] are coming from? None of the existing code creates byte[], more importantly, it shouldn't have a length of 100827136..

    #Update
    I tried checking memory on Android, I don't see the same System.Byte[], however, there is still memory leak as the same scene will eventually crash without interaction.. I am unable to find out where the leak is coming from.
     
    Last edited: Sep 14, 2022
  2. mrm83

    mrm83

    Joined:
    Nov 29, 2014
    Posts:
    324
    Yes i am.

    The leak is also random. Sometimes it happens within 5 minutes, sometimes it doesn't happen in hours.

    I can't pinpoint where it is coming from except for the suspicion that this is a unity thing.
     
  3. MartinTilo

    MartinTilo

    Unity Technologies

    Joined:
    Aug 16, 2017
    Posts:
    1,870
    What is referencing these byte []? And are you opening any memory snapshots while this increase is happening?

    Because the memory Profiler UI currently loads the entire managed heap as managed byte [] into memory, so if you are taking a snapshot while a snapshot is open, you're exponentially growing your managed heap usage.
     
  4. mrm83

    mrm83

    Joined:
    Nov 29, 2014
    Posts:
    324
    Yes, I had the snapshot opened.

    I realized byte[] wasn't causing the memory leak and crashing, it is something else.

    But I am unable to pinpoint what is causing it with profiler or memry profiler.

    Before upgrading to 2021, I've seen console message stating there was memory leak with a collection or something like that in 2020. the message no longer appeared in 2021 but there are random screen freeze crashing (but sound is working).