I am afraid this: v, c.L[j] = c.L[j][0], c.L[j][1:] is a memory leak (sorta). It would not be an issue if the slice elements were say int or float though.
Two ways to loose memory here: 1. String can "never" be GC-ed. This is the worst one. 2. Zero-th element of the slice is lost until the slice is fully reallocated. I _think_ you cannot just re-slice to reclaim/reuse this memory.
The right way to do what you wanted is this: v, c.L[j], c.L[j][0] = c.L[j][0], c.L[j][1:], nil
no subject
Date: 2024-05-08 09:23 pm (UTC)I am afraid this:
v, c.L[j] = c.L[j][0], c.L[j][1:]
is a memory leak (sorta). It would not be an issue if the slice elements were say int or float though.
Two ways to loose memory here:
1. String can "never" be GC-ed. This is the worst one.
2. Zero-th element of the slice is lost until the slice is fully reallocated. I _think_ you cannot just re-slice to reclaim/reuse this memory.
The right way to do what you wanted is this:
v, c.L[j], c.L[j][0] = c.L[j][0], c.L[j][1:], nil
no subject
Date: 2024-05-09 07:42 am (UTC)Eg
v, c.L[j], c.L[j][0] = c.L[j][0], c.L[j][1:], nil
c.L[j][0] on the left - does that refer to the c.L[j] before or after assignment of c.L[j][1:] to it?
no subject
Date: 2024-05-09 12:36 pm (UTC)These assignments work like they do in SQL update. Everything to the left of "=" is "after" the change and everything to the right is "before".
If course, I could write a quick test and/or even dig up a link to the relevant place in the spec. Please forgive me for being too lazy.