Will objects used in Physics.IgnoreCollision be garbage collected?

When I register 2 objects to never collide with each other using Physics.IgnoreCollision, will these objects ever be garbage collected?

A common use case is to have e. g. bullets to not collide with another object. So these bullets would be instantiated over and over and registered to not collide. Hence my concern.

I know I could put the bullets on another layer, but my thoughts are more if I should use Physics.IgnoreCollision at all in case these objects are never garbage collected.

I’m going to say yes they will be. I tried to confirm this by examining the decompiled Unity source code, but IgnoreCollision is an extern call so I can’t see what it does. Here’s why I think they will be collected though.

First, it would be a glaring oversight on behalf of Unity if they were not and it wasn’t mentioned in the docs at the very least.

Second, I put together a little test which seems to suggest that they are. I put together a scene with 5000 objects that call Physics.IgnoreCollision with all other objects. They are then destroyed after 5 seconds. Using the builtin Profiler I took note of the amount of garbage allocated before and after they were destroyed, the number of physics bodies, and how much processing time the Garbage Collector used. I then repeated the test but did not ignore any collisions. The profiler reported the same information in each case. Not the most rigorous test, but it’s good enough for me.