I’ve encountered an issue when creating MaterialPropertyBlock and assigning two Vector4 arrays to it using SetVectorArray, they never have more than 20k items in them, and the memory usage increases by about 100mb every second or two (so a huge leak).
I have a huge array of few hundred thousand to a million objects, I process the gameplay-related stuff in Burst Job, do a CPU frustum culling down to ~10k that will be displayed on the screen at once, do another Job to create Matrix4x4s and render using Graphics.RenderMeshInstanced(). This works perfectly fine, in standalone builds it uses maybe 70mb of memory and runs at up to 800 fps. I tried to add per-instance color variations based on the state of the object so when calculating Matrix4x4s I also output some Vector4s for the colors and pass them to MaterialPropertyBlock which I assign to my my RenderParams object before the rendering. This causes a huge memory leak as described above. In Memory Profiler this is counted as Native memory and when inspecting it shows Unity Subsystems → Unkown → Unkown. If I remove the SetVectorArray function calls it goes back to the previous sub100mb result even if I still create and assign an empty mpb every frame.
I’m interested in either fixing the leak or finding an alternate solution to what I want to achieve. This is the first time I’m doing anything with Graphics API so please excuse me if I’m missing an obvious solution.