2019 - GC aggressiveness

Just switched to 2019 and noticed the GC is behaving very aggressively in the editor - as in it will trigger for every about 5M of allocation - way more aggressive than it was in 2018.2 which is what I’m coming off.

Now I love all the new GC features we got for 2019 and it’s the main reason for switching to it. However both useful features (disabling the GC and incremental GC) don’t work in the editor yet.

So I’m hit with about a 1s break every 15s or so (I have some debug output that does generate a lot of garbage) which … let’s just say hinders development efforts …

Is there any trick to get the GC to be more tame? Ideally I’d let it go up to 1/2G before kicking in during development in the editor.

Solving GC allocs is not an options I guess?

You can try disabling GC at all, and manually collecting it once some value is reached. Although I’m not sure if new API for garbage collector does work in the editor. You might want to try out that yourself via UnityEngine.Scripting.GarbageCollector API.

Also, I’m glad that it does happen. Unity Editor went out to the swap space / memory too often.

Well, disabling GC doesn’t work in the editor (unless I’m doing something horribly wrong).

The allocations come from my debugging output which I need … while debugging. I have the build part covered with the new features in 2019. But GC every 5 min in the editor is very … unproductive :slight_smile:

I’ll test it on a 2nd machine and see if there’s something specific to my initial test. GC every 5M doesn’t sound right.

There’s probably something else. I suggest profiling if the GC is not related to the debug output.

If it is… Well then, maybe its time to implement some tools to help doing exactly that.
Most of the garbage usually comes from writing string / logs. Exposing a variable to the inspector / outputting it to the custom window, or decreasing output ratio might be a good solution.

Also, don’t forget that Unity’s is capable of exposing backing fields if the inspector is set to the Debug instead.

Well, couldn’t find a way to fix it. I can manage it in the player by running the GC on demand but it’s really annoying in the editor (where you don’t have any of the cool new GC stuff).

It seems to constantly trigger every new 5M of garbage. I can control that to some degree by controlling the amount of garbage but it still has an impact on productivity.

Hopefully this will get solved when the new GC stuff becomes available in the editor as well (2019.2? fingers crossed!). However I suspect a bug in the GC as well - can’t believe someone actually intended for the GC to be this aggressive?