There are and have been lot’s of threads on API calls and Asset Store code that is not optimised for use with the Unity GC this thread is aimed at thinking about the workload the Unity API places on the GC.
A GC has to scan all memory objects for live references so that it can work out if an object can be removed and it’s memory freed up.
Unity has some big and possibly some very GC unfriendly classes.
MonoBehaviour is a key class that we extend nearly all our component code from.
It’s main complexity seems to be it’s Messages section Unity - Scripting API: MonoBehaviour
Note that it’s complex interplay of Start()/Awake() and On() messages can make it complex to use and recycle from a managed pool.
Probably the most complex class from a GC perspective is the Transform class as this is also potentially the root or a branch in the a hierarchy of other transforms.
Note also the tight intertwining of object and component hierarchies, Unity has always had problems with nested prefabs and I wonder if this could be part of the problem.
Also there is the GameObject class which allows you to traverse the component/transform hierarchy and find other components up or down the tree.
So you can infer from this that a component based approach to game development using Unity can quickly become a spaghetti western of references to sub components within hierarchies and across hierarchies.
E.g.
Cowboy has hat, boots, gun (Weapon class), bullets (Damage/Missile class) and is controlled by the Cowboy-Controller.
Indian has feathers, moccasins, bow (Weapon), arrows (Damage/Missile class) and is controlled by the Player.
Both have a hit collider and Health class.
The Cowboy also needs a Sensor (class) and trigger volume to detect the player as a target.
Even in this simple static example (no animation/particle fx or even meta game scripts have been mentioned) you can see a network of connections are needed between components.
So from a GC perspective is this a complex and even memory heavy way to run things?
Or does Unity need a GC that works well with complex component hierarchies?