2
0
mirror of synced 2025-02-22 14:28:14 +00:00

bind: use runtime.KeepAlive to keep foreign references alive

With Go 1.8 to be released, runtime.KeepAlive is now necessary to
make sure a reference to a foreign object is not garbage collected
and finalized before we get a chance to increment its reference
count.

runtime.KeepAlive was introduced in Go 1.7 which is the minimum
version required by gomobile.

Change-Id: I32215f96e4f415ff9be7b979dd3677e067b8d201
Reviewed-on: https://go-review.googlesource.com/35954
Reviewed-by: David Crawshaw <crawshaw@golang.org>
This commit is contained in:
Elias Naur 2017-01-29 12:53:23 +01:00
parent 44ced21510
commit 959f80f9a9

View File

@ -102,6 +102,9 @@ func FromRefNum(num int32) *Ref {
func (r *Ref) Bind_IncNum() int32 {
refnum := r.Bind_Num
IncForeignRef(refnum)
// Make sure this reference is not finalized before
// the foreign reference count is incremented.
runtime.KeepAlive(r)
return refnum
}