Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice

Physics generating unexpected garbage.

Discussion in '2018.1 Beta' started by georgeq, Apr 13, 2018.

  1. georgeq

    georgeq

    Joined:
    Mar 5, 2014
    Posts:
    662
    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. rz_0lento

    rz_0lento

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

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    6,609
    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
  4. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    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:
    3,135
    Could you please profile the player and see if this allocation occurs there as well?
     
  6. PhilSA

    PhilSA

    Joined:
    Jul 11, 2013
    Posts:
    1,926
    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
     
    LoneDev6 likes this.
  7. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,450
    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:
    662
    2018.1.0b13
     
  9. georgeq

    georgeq

    Joined:
    Mar 5, 2014
    Posts:
    662
    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:
    662
    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:
    3,135
    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.