517 B
517 B
Hints
-
millionsslice's backing array uses 65 MB of memory. -
makea new slice with 10 elements with a new backing array.-
copythe last 10 elements of themillionsslice to the new slice. -
So you will have slice with a new backing array only with 10 elements.
-
Then overwrite the
millionsslice by simplyassigninglast10slice to it.
-
-
Remember: slice ~= pointer to a backing array.
If you overwrite the slice, it will lose that pointer. So Go can collect the unused memory.