You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The cases that matter are where you have a parameter or local variable that is pointer to some type, there is or might be a finalizer on the object, the last reference to the object in the function is passing a field to some other function, and the finalizer might in some way invalidate that field value.
It would be nice if go vet could detect these situations, especially if it ends up being run on std regularly (eg. on trybots).
My proposal to make it possible is to add a tag vet:”finalizer_invalidate" to struct fields that matter in this context; with this tag, vet should be able to detect the missing calls to KeepAlive with no false positives.
The text was updated successfully, but these errors were encountered:
Nobody should use finalizers, so nobody should need this. Even if this sort of vet rule were easy to write (it won't be), I don't think we need to encourage the use of finalizers by making them easier.
There have been a couple of CLs in which @ianlancetaylor has manually added
runtime.KeepAlive()
after careful code inspection:In Ian's words:
It would be nice if
go vet
could detect these situations, especially if it ends up being run onstd
regularly (eg. on trybots).My proposal to make it possible is to add a tag
vet:”finalizer_invalidate"
to struct fields that matter in this context; with this tag,vet
should be able to detect the missing calls toKeepAlive
with no false positives.The text was updated successfully, but these errors were encountered: