How to reproduce:
- Open the attached "IN-148671" project
- Open "Scenes/SampleScene"
- Open Window > Analysis > Profiler and enable "Deep Profile" and "Clear on Play"
- Enter Play mode and pause once the on-screen benchmark graph appear
- In the Profiler CPU Usage chart, select the first captured frame (it can be even without visible spike)
- In the bottom pane, switch the view dropdown (top-left) from "Timeline" to "Hierarchy"
- Type "Child" in the search field (top-right of the pane)
- Observe the "GC Alloc" column for the "Transform_Dot_ChildrenForeach()" and "Transform_Dot_ChildrenFor()" rows
Actual result: “Transform_Dot_ChildrenForeach()” shows non-zero GC Alloc, while “Transform_Dot_ChildrenFor()” (identical work) shows 0 B
Expected result: Iterating a Transform's children with “foreach()” allocates no managed memory, like the “for()” loop
Reproducible with: 6000.0.0f1, 6000.0.81f1, 6000.3.21f1, 6000.5.7f1, 6000.6.0b7, 6000.7.0a4
Reproducible on: Windows 11 (25H2)
Not reproducible on: No other environments tested
Workaround: iterate with an index loop instead “for (int i = 0; i < parent.childCount; i++)
{ var child = parent.GetChild(i); ... }
” GetChild returns the child without allocating an enumerator