eygraber
07/04/2018, 5:46 AM<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
?spand
07/04/2018, 5:49 AMcopy
allocates a new object as the name suggests. If there is no need for a copy then mutating the property might be a good ideaedwardwongtl
07/04/2018, 5:52 AMvar
in this case, it can save lots of memory if your object is huge.