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. Dismiss Notice

Question Memory leak?

Discussion in 'Scripting' started by ChuckieGreen, Jan 31, 2023.

  1. ChuckieGreen

    ChuckieGreen

    Joined:
    Sep 18, 2017
    Posts:
    349
    Hi, I think my game might have a memory leak but I have no idea how to track the issues. I am using the memory profiler, and it says i have almost 3gigs of system.byte, which seems insane cause my game is quite small. The biggest assets in my game is a bunch of images which only take up 326mb, so the almost 3 gigs doesnt seem right. I am not really familiar with the memory profiler or memory managment in general. Is there somewhere in the memory manager that will help me figure out what the issues are?

    image if it helps
     

    Attached Files:

    Last edited: Jan 31, 2023
  2. MartinTilo

    MartinTilo

    Unity Technologies

    Joined:
    Aug 16, 2017
    Posts:
    2,096
    Hello,
    If you select that block of Byte array memory in the tree map, or if you filter the All Managed Objects table by type (clicking on the column header) of Byte [], you should see a list of all these byte arrays. You can select each if them and check the references panel on the right side to see what is holding on to them, and if it should.

    Likely some script of yours is creating these and never removing it's reference to them, so that the garbage collector can't get rid of them.
     
  3. ChuckieGreen

    ChuckieGreen

    Joined:
    Sep 18, 2017
    Posts:
    349
    Thank you for the response. I am looking at the list of byte arrays just now, and it doesnt seem to be anything involving my scripts etc. It seems to all link to memoryProfiler. I am not sure if i am maybe looking at the wrong area. I have included a picture of what I am looking at, is this the right section? Thanks for any help
     

    Attached Files:

  4. MartinTilo

    MartinTilo

    Unity Technologies

    Joined:
    Aug 16, 2017
    Posts:
    2,096
    Ah, yes, when you capture the editor with a memory snapshot open in the Memory Profiler, that can indeed include a bunch of byte array data (about the same amount as the managed data in the snapshot). In 1.1.0 (not yet released) we changed it to load the managed heap data as native memory for efficiency and to not clutter the capture like this.

    I'd recommend to make a development build, attach the memory profiler to it and take a snapshot of that for a cleaner analysis.

    You can also use an empty project with Unity 2022.2 and version 1.0.0 of the Memory Profiler package to attach that to your build and capture snapshots (or import them over from your main project) to get the newest changes for the package.
     
    Bunny83 and ChuckieGreen like this.
  5. ChuckieGreen

    ChuckieGreen

    Joined:
    Sep 18, 2017
    Posts:
    349
    Oh thank you, I didnt know I could attach the profiler to the build. I really need to look more into what the profiler can do. But thank you for the help, I will try that now.
     
    Bunny83 and MartinTilo like this.