Does `<data class>.copy` do anything special...
# announcements
e
Does
<data class>.copy
do anything special in terms of GC, or is it the same as allocating a new object? If I have a list of objects that are instances of data classes in a performance critical part of my code, and I need to routinely update the value of one of their fields, would I be better off making it a
var
and updating it in place, or using
copy
?
s
copy
allocates a new object as the name suggests. If there is no need for a copy then mutating the property might be a good idea
👍 1
e
I would use a
var
in this case, it can save lots of memory if your object is huge.