Thank you for submitting your inquiry.
You can track the status of your inquiry here.
You may want to save your case's ticket: 590565_hi2j38paob5vp4cg


    (Closed) -e We were profiling (deep profile) our game to check about
     
     
     
    5
    -e We were profiling (deep profile) our game to check about cpu and garbage generation when we found out that GetComponent() was generating garbage in some cases. After making some tests we discovered that it was when the component is not found and GetComponent() returns null.

    We attached a project showing the bug.

    The project consists of two scenes:
        •    GarbageTestCaseScene - it has a GameObject with a component/behaviour calling GetComponent() multiple times per update while the asked component is missing.
        •    NoGarbageTestCaseScene - it has the same component/behaviour but it asks for a component that exists on that GameObject.

    To replicate the bug run the first scene and start profiling and you will see that a lot of garbage per frame is generated while on the other scene this doesn't happen.
    The question is, should this be happening? Why? We know it is not recommended to call GetComponent multiple times per update but we need it in some cases and we are willing to pay the CPU cost but not the garbage generation one.
    The test cases were tested using Unity 4.3.4f1 pro and 4.3.2f1 free.
    More info at http://answers.unity3d.com/questions/636278/should-getcomponent-generate-garbage-when-the-comp.html and https://github.com/acoppes/unity-getcomponent-gc-test
    Thanks.

     
       
      To follow up on this case, send email to bugs@unity3d.com mentioning 'Case 590565' in the subject.
      Your Cases:
      Case Title Status Date Opened
      1303144 Using invalid default keys for shortcuts will break the shortcuts forever Closed 1/2/2021 9:17 PM
      1287664 There is a NullReferenceException with ClearPreviewCache() method Closed 10/25/2020 10:21 PM
      1287660 Sprite Library Asset render bug on Inspector Closed 10/25/2020 10:10 PM
      893309 Crash when activated deep profile mode Open 3/21/2017 2:50 AM
      828019 Unity crashed while debugging in MonoDevelop Closed 9/1/2016 4:20 AM
      590565 -e We were profiling (deep profile) our game to check about Closed 2/10/2014 7:08 PM