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
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Random 40MB unaccounted for

Discussion in 'Editor & General Support' started by MatthewLeeFarmer, Oct 31, 2012.

  1. MatthewLeeFarmer

    MatthewLeeFarmer

    Joined:
    Jul 31, 2012
    Posts:
    14
    Hello!

    So I'm developing a project for the iPhone for about 5 months now. We tested our build on an iTouch 4th gen device sometime in September and we were getting around 80MB in memory usage. Today, we're getting around 120MB, which inevitably crashes. We got this information from Xcode>Instruments>Activity Monitor.

    Now, we connected this up to the AutoConnect profiler to check out what memory allocation was. After adding up all memory numbers (Total, Textures, Meshes, Materials, etc) we reached a lower number. Nearly every time, it would be a discrepancy of about 40MB (once, 36MB).

    We've been racking our brain to no avail as to the cause. I removed all textures from one scene and the memory usage went down 10MB in both profilers. The number of changes between here and a month ago are pretty big, so removing them one by one isn't an option. Anyways...Here's my questions:

    1. Is there any way to find out what is allocating that space?
    2. Is there any common culprits of this sort of memory allocation? Garbage Collection? using System.DateTime; or something?

    Oh, one thing to note is that we Load to a completely blank scene and asynchronously load levels after that. Oddly enough, in the editor, profiler reveals that I have used 13MB even before the other levels load. Loading to a blank scene should clean memory, correct?
     
  2. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    loading a blank scene should clean memory, yes. But it can not clean or touch the memory required to load and maintain the application code in memory which on iOS is a must (on mobile in general) as they have no paging. Either it fits into ram or gets killed.
     
  3. MatthewLeeFarmer

    MatthewLeeFarmer

    Joined:
    Jul 31, 2012
    Posts:
    14
    I'm definitely not asking if our game is clearing out iOS memory to fit our 120MB size. I'm wondering if our game should really be 120MB.

    The way I counted metrics was to start with what Instruments provided, which was 123.7MB.
    Now, the AutoConnect Profiler gave us something like the following information:

    Adding all these numbers up totals to about 84 MB. So there's around 40 MB discrepancy between Instruments AutoConnect Profiler in Unity.

    1. Is this normal? or even accurate method? Is there an accurate method?
    2. Is there a way to reduce that 40 MB?
     
  4. MatthewLeeFarmer

    MatthewLeeFarmer

    Joined:
    Jul 31, 2012
    Posts:
    14
    Just as a quick update:

    I ran a Debug line that spit out Profiler.usedHeapSize System.GC.GetTotalMemory() so I could see what Unity Mono was using.

    Mono went from around 500,000 to 1,200,000. It would go up up from around the 500k mark to the 1.2m mark, then fall down again.
    Unity was around 20-30 million depending on the scene. Again, this doesn't seem to match the Instruments Activity monitor reading of 110-120MB per scene load.

    We're at wits end on how to solve this memory crisis. Anybody have any ideas?
     
  5. GamerVJ

    GamerVJ

    Joined:
    Apr 6, 2011
    Posts:
    7
    Hi,

    Did you found any solution to this?? I am stuck at same situation.

    Thanks,
    VJ