Since unity will not allow users to iterate over mesh.uv and mesh.vertices, I am stuck having to use GC intensive calls when applying an array of uvs and vertices to a mesh. I run into high GC allocation because every time I rebuild a mesh, the uv and vert arrays will be a different size due to the mesh being modified. In turn, this results in having to resize or create new uv/vert array and that is where the garbage collection comes in to be a problem when the old array or list is discarded as well as when applied to the mesh.
Example 1 - List: For example, building a List UVList for a mesh that is built frequently will require calls of UVList.Add(Vert), this creates garbage for the GC whenever the List is resized with List.Add because when the list is resized, it creates a new copy and the old copy goes into GC. Also, to apply this list to a mesh.uv requires the call UVList.ToArray(); which is a nasty call that creates huge GC if you have a long list of vertices because again, to convert to array, that array after it is copied mesh.uv = UVList.ToArray() the UVList array created goes to GC.
Example 2 Array: I've instead tried using fixed array sizes but then learned that you cannot iterate over vertices or uv array of a mesh. For example, using a for loop to directly apply a vertices array to mesh.vertices will result in no mesh showing (i.e. for(i = 0; ...){ mesh.uv[i] = uvArray[i];} )
If I cannot do this, then I run into the same problem as example 1, because the only way is to create new array every time you want to update your mesh that has diff uv/vert length. Resizing array requires creating a new copy of it, and then you have the same issue with GC.
I tried reading through this example of someone else dealing with Unity GC when frequently updating meshes http://gamasutra.com/blogs/RobertZubek/20150504/242572/C_memory_and_performance_tips_for_Unity.php
He doesn't really explain his helper method in applying the UVs to the mesh and when trying from his example, it also results in GC.
I guess my question is, how can I frequently update a mesh with diff uv/vert array size without running into GC Alloc slowing down my project?