CreateLines: Browser freezes after a while

In my example I dispose and create lines. After a long period the browser freezes a while if I want to close it. You get the effect earlier if you set MAX to 300. Is it a problem of javascript (garbage collection)? How can I avoid such side effects? I just want to draw simply a line between to points…

Yes it’s most probably the garbage collector as your are creating a line system each frame.

You should instead create it a single time and pass the instance you create the first time to all subsequent re-creations: the system will reuse the same system and will simply update the vertex positions with the array you pass in.

Also, don’t do new BABYLON.Vector3(...) for your 100+ vertices each frame. Create a fixed array of 100 Vector3 instead and update this array.

Generally speaking, creating new objects each frame is very bad in javascript, you will make the GC kick in often and “pause” your app meanwhile.

1 Like

image

… not really clear but update lines without disposing them! ^^

References:

… wondering why CreateLines() does not need a scene! :face_with_monocle:

If you don’t pass a scene, it will automatically use the last scene created.