DEV Community

[Comment from a deleted post]
 
maixuanhan profile image
Han Mai • Edited

Dude, you went too far. I was talking about the performance. When you said "a leak means that you mess up with the garbage collector", I know you wouldn't care enough. Leak in JS can be very simple that you create and hold too much memory but don't release them after used, or maybe global mem. Do you even know that the two example you gave are totally different in logic? One is creating 6-elem array many times, one is appending many elements in a single array. It depends on the developer's need, he can either modify or clone the original array. If he needs handy, your way will be better because of least effort (still wrong in logic in that example). If he needs performance, go the other way. If he wants to preserve the original array, then clone, if not, do on the current existing one, release it eventually.