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 Persistent allocation memory leaks

Discussion in 'Entity Component System' started by Rupture13, Sep 25, 2023.

  1. Rupture13

    Rupture13

    Joined:
    Apr 12, 2016
    Posts:
    129
    Aloha!

    After running my game with leak detection on, I get errors about memory leaks. These stem from persistent allocations. I can find the origins of these leaks via the full stack traces and fix them.

    However, I am wondering how much of an issue these leaks are. They are not growing during the game's lifetime (and thus not increasingly consuming memory from my PC). They are simply persistent allocations made once and then never disposed. I understand that these should be fixed, but in terms of severity, do such allocations realistically cause any problem?

    Hypothetically, when the game is shipped with these allocations unresolved and the user closes the game, aren't all these allocations thrown away when the process closes anyways?

    To reiterate, this is mostly a priority thing: I want to know whether I should spend immediate attention on these allocations/leaks.

    Cheers :)
     
  2. davenirline

    davenirline

    Joined:
    Jul 7, 2010
    Posts:
    941
    I think you should still dispose them at some point like on destroy of the system. We don't know the details of how the memory manager of these persistent allocations are handled. They may not seem to be a problem but during iteration of the game, those memory allocations might not be freed or there may be other side effects. If you have enough of this in many parts of your game, the editor could crash frequently and this would be annoying. Even if this is wrong, still err to the side of caution.
     
    Rupture13 likes this.
  3. msfredb7

    msfredb7

    Joined:
    Nov 1, 2012
    Posts:
    143
    Yes, a memory leak is a memory chunk you allocate for the entirety of the process's lifetime. So if your game does not continuously make new leaks during its runtime, you should be ok.

    However as davenirline said, this can have a different effect in the editor since the process is not terminated when you restart a game.
     
    Last edited: Sep 27, 2023
    Rupture13 likes this.