Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Fatal error in gc Too many heap sections

Discussion in 'Scripting' started by the_gnoblin, Aug 28, 2010.

  1. the_gnoblin

    the_gnoblin

    Joined:
    Jan 10, 2009
    Posts:
    722
    Hello!

    I've left my webplayer build hanging in my browser for a night, and in the morning I found and error

    "Fatal error in gc
    Too many heap sections"

    Is there something I am possibly doing wrong with memory?

    thanks for any tips.
     
  2. Emon

    Emon

    Joined:
    Aug 27, 2010
    Posts:
    35
    A quick search indicates it's probably a bug in Mono's garbage collector. Probably nothing you can do but wait until Unity 3 and hope that a newer version of Mono fixes the problem.
     
  3. Tak

    Tak

    Joined:
    Mar 8, 2010
    Posts:
    1,001
    Hi,
    Are you allocating a lot (like hundreds of thousands+) of small arrays, or something similar?
     
  4. TerXIII

    TerXIII

    Joined:
    Sep 4, 2010
    Posts:
    184
    It's probably due to memory allocation within the update() function. I'd really avoid creating new objects within the once-per-frame functions.

    Instead, keep a private member function to store the things you need to create between frames, and only create new ones when they are needed.
     
  5. demonicmetal cs

    demonicmetal cs

    Joined:
    Feb 11, 2010
    Posts:
    68
    i have the same problem in this part

    Code (csharp):
    1. public var iUser = new DemoData[100];
    Code (csharp):
    1. class DemoData
    2. {
    3.      var name : String;
    4.      var id : int;
    5.      var x : float;
    6.      var y : float;
    7.      var z : float;
    8.      var Rx : float;
    9.      var Ry : float;
    10.      var Rz : float;
    11.      var hasrigidbody : boolean;
    12.      var Vx : float;
    13.      var Vy: float;
    14.      var Vz: float;
    15.      var childeren : int;
    16.      var iChild = new ChildData[100];
    17. }
     
  6. maxmag

    maxmag

    Joined:
    Dec 25, 2010
    Posts:
    1
    Getting the same problem with the game "Milmo"

    after playing an average time of 1 hour, then, after the message, the plugin stops workin...
    T_T


     
  7. Mauri

    Mauri

    Joined:
    Dec 9, 2010
    Posts:
    2,663
    Please look at the MilMo-Forum for this error. This here might be a not so good place.
    As you can see the problem is already known.
     
  8. Games-Foundry

    Games-Foundry

    Joined:
    May 19, 2011
    Posts:
    632
    We've just hit this on our project, and unfortunately it happens after just a few minutes of gameplay. I just hope UT release the new GC implementation in 3.5.
     
  9. XeviaN360

    XeviaN360

    Joined:
    Jun 3, 2010
    Posts:
    181
    The same here. Is there a method to monitor/measure the heap memory?
     
  10. Ntero

    Ntero

    Joined:
    Apr 29, 2010
    Posts:
    1,436
    If you have Pro, you can either use the Profiler or use the underlying C functions:
    Code (csharp):
    1.  
    2. [System.Runtime.InteropServices.DLLImport("__Internal")]
    3. static extern long mono_gc_get_used_size();  //Amount Used
    4.  
    5. [System.Runtime.InteropServices.DLLImport("__Internal")]
    6. static extern long mono_gc_get_heap_size(); //Total Amount
    7.  
    These are Thread-Safe and tell you the Total Heap size, and how much is currently being used. I know on iOS the total heap doesn't go down, which is a problem as a large allocation block can permanently increment total memory used, even if general memory usage is lower.

    This is only for the Managed code, and no C++ or underlying Unity engine code will be factored into these totals. Not sure if there is also a call to measure how many individual objects are being used by the GC, but if I find one I'll post it here.

    Edit:
    http://www.acm.ndsu.nodak.edu/hosted/longjoel/mono-2.4/docs/deploy/mono-api-gc.html
    Nothing looks to expose a Total Object count that I can see.

    Edit: As far as reviewing these values, you want to keep Total as close to Used as possible, and should generally see a very gradual increase in Used up until it reaches Total and then a Cleanup back to some base position. If Used doesn't move at all you are at ideal conditions and are not creating any per frame garbage.
     
    Last edited: Oct 3, 2011
  11. amigojapan

    amigojapan

    Joined:
    Jan 22, 2013
    Posts:
    1
    Thanks a lot! this solved my problem...
    at first i had no idea how to fix it, but I took all the object generating and deletion I had in update and replaced it with only generating things when needed (when the user pressed space) and the program stopped crashing