Search Unity

  1. Going to #UniteBerlin? Bring a buddy & get 25% off the 2nd ticket! More info here.
    Dismiss Notice
  2. Famed game designer and creator of The Sims, SimCIty, and Spore is looking for a 3D artist to join their team. Join the challenge.
    Dismiss Notice
  3. Unity 2017.4 has arrived! Read about it here.
    Dismiss Notice
  4. ARCore is out of developer preview! Read about it here.
    Dismiss Notice
  5. Magic Leap’s Lumin SDK Technical Preview for Unity lets you get started creating content for Magic Leap One™. Find more information on our blog!
    Dismiss Notice
  6. We've opened a new World Building sub-forum to faciltate all your world building discussions! Drop in and ask any ProBuilder, ProGrids, or PolyBrush questions.
    Dismiss Notice
  7. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice

Physics generating unexpected garbage.

Discussion in '2018.1 Beta' started by georgeq, Apr 13, 2018 at 10:52 PM.

  1. georgeq

    georgeq

    Joined:
    Mar 5, 2014
    Posts:
    210
    I would never expect garbage generated from OverlapBoxNonAlloc, the name itself implies it, however It generates 120 bytes of garbage.

    boxna.png

    Another feature that generates garbage but shouldn't is RaycastHit.collider, as you can see below.

    scast.png

    The garbage is generated by a call to FindObjectFromInstanceID. For some reason this last function sometimes, not always generates 40 bytes of garbage.
     
  2. rizu

    rizu

    Joined:
    Oct 8, 2013
    Posts:
    93
    Which Unity version?
     
  3. Peter77

    Peter77

    Joined:
    Jun 12, 2013
    Posts:
    1,943
    Do not profile in the editor. The editor comes with overhead. For example GetComponent calls that don't return any Component, normally allocate a ton of garbage in the editor, which is completely gone in a build. There are various other cases where this is true in the editor.

    Profiling the game running in the editor is quite inaccurate, profile a build on the target hardware instead.

    That being said, I don't remember having seen FindObjectFromInstanceID ever. If that method is new, there is a chance that it's creating garbage memory. However, I still recommend to check that in a build as well.
     
    Last edited: Apr 14, 2018 at 7:16 AM
  4. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    21,486
    Do you have a case number you can drop in the thread so friendly curious staff take a peep?
     
    LeonhardP likes this.
  5. LeonhardP

    LeonhardP

    Unity Technologies

    Joined:
    Jul 4, 2016
    Posts:
    688
    Could you please profile the player and see if this allocation occurs there as well?
     
  6. PhilSA

    PhilSA

    Joined:
    Jul 11, 2013
    Posts:
    766
    A simple GetComponent may generate garbage in editor but not in build (apparently it's because it creates some internal debug string warnings if the component was not found, etc....)

    It's very possible that in this case, OverlapBoxNonAlloc tries to do some GetComponents internally too
     
  7. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    1,312
    Although I cannot say exactly what it is you're seeing here, know that AFAIK the managed object wrapper (that binds to the native object) is created when you first access any GameObject or Component (any object really). This isn't created each and every time, it's only created once for its lifetime. This may be what you're seeing and shouldn't be a continuous GC penalty.
     
  8. georgeq

    georgeq

    Joined:
    Mar 5, 2014
    Posts:
    210
    2018.1.0b13
     
  9. georgeq

    georgeq

    Joined:
    Mar 5, 2014
    Posts:
    210
    I'm not seeing it every frame, is more like once every second or two, and not at a regular intervals, but certainly more than once.
     
  10. georgeq

    georgeq

    Joined:
    Mar 5, 2014
    Posts:
    210
    No, on the player build I'm not getting any garbage as fas as I could test, so I guess is a false alarm.
     
  11. LeonhardP

    LeonhardP

    Unity Technologies

    Joined:
    Jul 4, 2016
    Posts:
    688
    Less severe for sure but not necessarily a false alarm. If you submit a bug report + repro project we can take a closer look at it.