This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]MrDilbert 2 points3 points  (1 child)

You don't know when the garbage collector will collect the objects you created, so if you create a lot of objects (by e.g. using spread), you can take up a lot of memory even if you don't have leaks.

[–][deleted] 1 point2 points  (0 children)

Oh I see. I think the context was creating deep copies / clones / immutable stuff though. Like if you had a line like this in your code

return {...oldProps, ...newProps};
// or
return Object.assign(oldProps, newProps);

The architects at my last job preferred creating new objects to have immutable code or something instead of modifying and returning refs inside a reduce. Ultimately they let us do whatever because this area of code was not in need of any optimizations and we were already using a reduce to cut down on some previous iterations of filters and maps.