DEV Community


Discussion on: Golang Garbage Collector 101

davidkroell profile image
David Kröll

Hi again,

I've done some additional research about the concepts and paradigm of the slice data type. Basically there are the three fields len, cap and data (the backing array you mentioned). As you already pointed out, there is more memory allocated than the cap and len (which are the same when using make) state.

These two values len and cap have to be stored also, in order to not access memory outside the bounds of the backing array. There is probably some memory usage hidden in these fields (as far as my understanding goes, this will only take two words of memory).

So where does the additional memory come from?
I believe this is to some extend based on the Go runtime. There is some space needed for the stack, Goroutine handling, the GC bookkeeping, and possibly many more.

Thread Thread
dev117uday profile image
Uday Yadav Author

I think its really good explaination of what's happening underneath. When i ran the program with s := make([]byte, 5000) it still show mem.TotalAlloc in between 80000 - 120000

finding resoure & explaination about this is bit hard, thanks you giving your time and sharing knowledge

i will update the article soon ( i have my uni exams coming up )