I’m memory profiling my game and i’m trying to explain something. There is a periodic increase in memory that seems to come from something other than my scripts. In the hierarchy i can usually see which script is responsible for an increase in allocated memory, but in this case it looks like it just doesn’t register. The GC allocated graph seems to confirm that this does not originate from my scripts, so what are other things that could be causing it? Does Total GC allocated include stuff from the engine? If so how do i find out what it is?
One caveat is that i’m running some background threads but as far as i can tell i disabled them all for this profiling round. I verified that if a thread other than the main tread allocates memory it will show up in Total GC but not in GC allocated. That being said, is there something else that will show up like this?
Well i finally found what was causing the allocations. Long story short: if the console says “The profiler has run out of samples for this frame. This frame will be skipped. Increase the sample limit using Profiler.maxNumberOfSamplesPerFrame”, don’t ignore it! The frame that was responsible for the allocations was skipped, causing the measurements for GC allocated to be dropped. But the allocations were visible in the next frame that was not skipped through total GC.
Long story long: we were running some background threads to do some heavy lifting. As i said before, it a background thread allocates memory the profiler won’t show it in GC allocated. So we made an option to run everything on the main thread. Of course you get terrible performance but the goal was to figure out which method was responsible for the memory. So now you have some updates that take a very long time. I don’t know the specifics of the profiler but my hunch is that it just checks what the main thread is doing every couple of nanoseconds and then attributes any time spent that way. Of course if a frame takes an excessive amount of time then you get the error quoted above, the profiler will run out of samples. The thing i missed every time is that it actually literally tells me that it skipped the frame. So the answer was to to exactly as the error suggested, i increased the maximum amount of samples.
And of course it makes sense that the frame that takes so much time that the profiler runs out of samples is the frame that allocates a huge amount of memory.