Grokking Advanced Go
0% completed
The unique and weak Packages
Keeping one shared copy of each distinct value, and having every user refer to that copy, is called interning. A weak reference is a pointer that lets code reach a value without keeping that value alive, so the garbage collector can still free the value when no ordinary pointer refers to it.
Both ideas save memory. They are also related, because a table of interned values should not keep a value alive after everyone has stopped using it. Go added the unique package for interning in Go 1.23, and the weak package for weak references in Go 1.24.
.....
.....
.....
Like the course? Get enrolled and start learning!
Reading Progress
0%