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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Strange memory usage

Discussion in 'Scripting' started by ameinfjg, Sep 6, 2018.

  1. ameinfjg

    ameinfjg

    Joined:
    Feb 14, 2017
    Posts:
    78
    Hi all,

    I'm investigating the memory allocation of our game. When monitoring with windows performance monitor the memory allocation appears to be generally increasing over time, which looks like a memory leak, but when I log the memory usage from the Profiling namespace in Unity I get a very different result. I'm guessing there's a missing piece of the puzzle in the interaction between Unity and Windows which I'd like to better understand. I've got some graphs to show what I mean. The use case is repeatedly moving between two, very different, scenes.

    This graph shows the total usage and total reserved memory, as reported by Unity, basically flat over time (after initialisation).

    This one shows the Working Set (total and private) as reported by Windows, which appears to be increasing slowly over the course of the test.

    If anyone can offer a suggestion as to what is happening here I'd appreciate it.
     
  2. MartinTilo

    MartinTilo

    Unity Technologies

    Joined:
    Aug 16, 2017
    Posts:
    2,198
    Hi,
    What version of Unity is this?
    And have you looked at this with the detailed memory snapshot in the Profiler Windows memory section? that is, taking a capture after entering the second level and then again after a couple of scenes switches and compare.
     
  3. ameinfjg

    ameinfjg

    Joined:
    Feb 14, 2017
    Posts:
    78
    This was using 2017.4.9f1
    I have done such a comparison and can find no difference (after the first iteration) which I think the top graph represents.
     
  4. MartinTilo

    MartinTilo

    Unity Technologies

    Joined:
    Aug 16, 2017
    Posts:
    2,198
    I'm assuming this is profiling a player build on windows and not the editor, running the game, right?

    I can't really see an explanation for it, except for maybe plugins that allocate memory that is not tracked by unity?

    Maybe the new memory profiler that will be released as preview during the 2018.3 beta might help track this down... Can you divide and conquer this, i.e. disable stuff until it is no longer present?

    Maybe this is a bug on our side as well but I can't really tell without knowingwhat the minimum reproduction case looks like.
     
    karl_jones likes this.
  5. ameinfjg

    ameinfjg

    Joined:
    Feb 14, 2017
    Posts:
    78
    I had completely failed to consider any plugins that were outside the scope of Unity. Presumably anything in mono would show up but anything native might not, is that correct?
     
  6. MartinTilo

    MartinTilo

    Unity Technologies

    Joined:
    Aug 16, 2017
    Posts:
    2,198
    Yep, anything that's native or otherwise unmanaged (e.g. there might be spillage in an unsafe context somewhere)