runtime: document that KeepAlive doesn't have anything to do with unsafe.Pointer safety rules #47562
Labels
Documentation
Issues describing a change to documentation.
FrozenDueToAge
NeedsFix
The path to resolution is known, but the work has not been done.
Milestone
There's nothing in the runtime.KeepAlive or unsafe.Pointer documentation to suggest they interact, but I've seen experienced Go engineers mistakenly interpret that runtime.KeepAlive can be used as a quick-fix for working around misuse of unsafe.Pointer.
This often happens to work today, but it's not guaranteed to be safe. In particular, misuse of unsafe.Pointer can lead to objects being allocated on the stack, which can result in unintended program behavior due to memory corruption: https://play.golang.org/p/s2G90hvQUOZ
We don't normally document what things aren't used for, but this seems like a subtle enough point to call out, IMO.
The text was updated successfully, but these errors were encountered: