After a few seconds there will be 5 extra materials. N.B. force dispose of material via mesh.dispose(false, true) has no effect on material dispose.
Not sure if I am doing sth wrong or whether my expectations are wrong. But I would expect if I let Babylon handle material creation/assignment it also handles cleanup.
I was also encountering a massive memory leak when using Greased Line. I implemented the above. Memory leak is now sorted by the CPU usage has skyrocketed. Before I was getting a solid 60FPS and now after the memory leak implementation I am getting below 20FPS when the greased line is drawing.
Are you able to setup a repro in the Playground? Just to be sure this is the problem, can you call dispose without any parameter and check if the problem disappears?
If I only execute this.greasedLine.dispose() then the CPU usage is all good, but there is a memory leak, and it will quickly grow to 4gb if I keep on drawing. If I make the change as per this thread and execute this.greasedLine.material!.dispose(); this.greasedLine.dispose(false, true); Then there is no memory leak, but the CPU usage is maxing out in the browser and the frame rate drops below 20fps. To confirm, when I call just dispose(), CPU usage goes back to normal, but the memory leak comes back. I have tried to use addPoints from the documentation instead of disposing and redrawing the entire line, but the addPoints method requires the options param with points again and also just does not draw the line.
I will see what I can do with regard to setting up a PG. I completely understand and agree that this is the best way to convey an issue.
I modified a simple playground to include what I am basically doing.
I can replicate the memory leak with just dispose() but not the CPU usage when using the workaround above. I will need to dig into my code to figure out what is causing the high cpu usage. Only real difference between mine and this playground is, I am importing a mesh for the vehicle, have dynamic terrain, skybox, ground material, have a perimeter drawn with a separate greasedline as well as a grid on the ground. All of which I have disabled in testing and still produce the high cpu usage. Anyway… Here is the playground.
I don’t know why the lines are jumping around whilst being drawn, but that isn’t the problem I am trying to convey, as I don’t experience this issue in my scene. Merely that it would appear that in Babylonjs 7.24.0, the Material still appears to not being disposed when calling only dispose on the GreasedLine.
I found out what was consuming the extra CPU Cycles. Unrelated to Babylonjs. But, using this.greasedLine.material!.dispose(); this.greasedLine.dispose(false, true); does use more CPU than just dispose() but just dispose creates a memory leak.