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.

Question Need help finding the source of a leak

Discussion in 'Scripting' started by InvincibleCat, Jun 28, 2023.

  1. InvincibleCat

    InvincibleCat

    Joined:
    Dec 23, 2014
    Posts:
    83
    Hello,

    I have been trying to hunt down a leak for quite a while now and I am getting a bit desperate as I am really close to launch.
    I should have seek for help sooner and I hope someone will be able to help me :)

    The game is a roguelike. I took 2 snapshots. I force the same seed so basically what I did is:
    Start run -> Take memory snapshot 1
    Got back to menu -> Start run (same seed) -> Take memory snapshot 2

    I have uploaded both memory snapshots here => https://drive.google.com/drive/folders/14RpYljV1b_eJ4k7BnUA7xBv2OWhNNs39?usp=sharing
    I hope this will be enough to find the source.

    Thanks in advance :)

    Cheers!
    -Tim
     
  2. KillDashNine

    KillDashNine

    Joined:
    Apr 19, 2020
    Posts:
    451
    Use the Profiler to find leaks. There is no straightforward answer but it is not very complicated to use and it will show you eg what's eating memory or CPU.
     
  3. MaskedMouse

    MaskedMouse

    Joined:
    Jul 8, 2014
    Posts:
    1,068
    The snapshots are from the new memory profiler.
    I find the old memory profiler easier to read out than the new one.


    There is an active bug
    https://issuetracker.unity3d.com/is...emory-leak-when-memory-profiler-is-in-project

    If you're creating UnityEngine.Object type of objects, destroy them once you're done.
    If you're using addressables don't forget to release the instances or asset once you're done with it.

    Are you sure you have an actual leak or are you just guessing?
     
    Bunny83 likes this.
  4. MartinTilo

    MartinTilo

    Unity Technologies

    Joined:
    Aug 16, 2017
    Posts:
    2,260
    This is a different issue. BTW, the mentioned bug is fixed in 2022.3.10f1 which is out today.


    I'd recommend updating to 1.1.x of the memory profiler and looking into all these Leaked Managed Shells
    Unity_O5IEktCOoI.png
    That References view improvement with the L! and F! buttons is not yet in 1.1 and needs more polish (e.g. icons instead of cryptic letters) but helped to show whats going on here:
    L! = Leaked Shell
    F! = Static Field root
    Refresh Icon = Circular reference, ignore

    Essentially, you are leaking Managed Shells because they are subscribed to static events on TtEvents and never unsubscribed
     
    Last edited: Sep 22, 2023