Hacker News new | ask | show | jobs
by _ph_ 1749 days ago
The array is only reallocated when it runs out of space. There is no magic about the "old" array. The GC just won't collect it, as long as a pointer to it exists.

I don't think there are many reasons, if any at all, to keep a pointer to an array element of a slice around in Go. Usually I only get the address of an array element only when passing it to some C code or doing some low level manipulation, but then I don't keep the pointer around. In Go code you usually just keep the slice object - which contains the necessary pointer anyway.

1 comments

Thank you for clarifying this. I was scratching my head reading this discussion, wondering why one would do this in the first place.