- Home /
The question is answered, right answer was accepted
GC Allocation with new array length
I'm using a mesh generator script and it creates vertex and normal arrays inside update because we're growing the mesh dynamically during runtime. So, we're using something like this: vertexArray = new Vector3[segments.Count * segmentVerts.Length];
And same for normal array.
Because the segment length increases through out the game (for a couple of minutes), the gc alloc goes upto 50kb and we see spikes regularly. I tried using List , adding values and then converting it back to array because the Mesh class accepts vertices, normals and uvs as arrays but that just made gc alloc heap worse. Does anyone have any suggestions for this issue?
you should definitely check out this link:
http://nothkedev.blogspot.com/2018/08/procedurally-generated-meshes-in-unity.html?m=1
the essence is: - use the $$anonymous$$esh Set-$$anonymous$$ethods - Use Lists - initialize those lists as big as thr final result
Follow this Question
Related Questions
force and delay Garbage Collection 7 Answers
Optimize (Garbage Collection, Memory usage) 1 Answer
Reasonable heap alloc. per second and total ? 0 Answers
Display numbers in UI.Text Garbage Free? 2 Answers
How do I get my game to run faster? 4 Answers