I had a similar problem and what I did was creating an array of "Identifiable Structs" with only 1 item with the coordinates. Every time I had new data, I replaced the struct in the array and because it has a new ID, it's updated accordingly.
It's almost the same that you are saying, but with your example, if you have too many lines, you start getting an error after approximately 600 lines.
With my solution, I did a test with almost 5000 lines, all in the same polyline without any problem.