- Home /
CPU being choked by GC.MarkDependencies
Hi y'all,
I was wondering if someone could help me out with an odd garbage collection behavior I'm seeing. I'm very new to Unity so forgive me if this ends up being dumb. We have a point in our project where the user can view what in our code ends up being a very large collection of objects (another player and all their assets). They can cycle through other players and each time they go to the next the previous one is unloaded. Going to the next causes a severe drop in the framerate and a huge CPU spike in the profiler that lasts for a few seconds and then goes away. Now, this sort of makes sense but what seems odd is that it's not GC.Collect that's causing the hit it's GC.MarkDependencies and it shows up in the profiler with the color for "other". I added an explicit call to GC.Collect after unloading the player that should complete before you could press the next button again but it didn't change the behavior at all. Any help on figuring out what's hijacking our CPU would be most appreciated.
Never heard of GC.$$anonymous$$arkDependencies.. didn't even find it in the System.GC class. (I even peeked inside the decomplied mscorlib.)
Nevertheless, it sounds as if the actual creation of the objects causes the spike, so my first attempt would be to figure out a way to create as few objects on the heap as possible.
What does the code look like?
Yeah, I was surprised that $$anonymous$$arkDependencies didn't get any hits at all in Google. I know what it's doing in theory but it seems odd that it has to take the processor for that long.
I'm not sure about all the code since I'm very new to it but the gist of it is that the previous player and all of their many, many subobjects are despawned and a new one is immediately created. I'm sure that's the root of the problem but I'm not sure why the marking process should take so long.
Yes, something like that needs to happen in the long run. What's happening now is pretty inefficient. Right now I'm looking to see if there's a quick fix that can alleviate the hitch we're seeing and try to understand what's making $$anonymous$$arkDependencies take several seconds.
I'd need to see some code to be able to tell you anything more.
Answer by kurtdog · Jul 29, 2017 at 10:42 PM
I'm having the same issue, huge gc.markdependcies spike in the CPU other section. For me it's when I disable a gameobject. I've optimized all the scripts on the object for GC performance (I think). Still getting the issue and can't tell what's causing it!
Your answer
Follow this Question
Related Questions
Intermittent slow downs in Unity - unrelated to garbage collector 1 Answer
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Invisible method costs? 0 Answers
ManagedHeap.ReservedUnusedSize 0 Answers