The core question is does a *uintptr *derived from a pointer to an object 
count as a reference as far as GC is concerned?
For example (https://play.golang.org/p/tA6Fsl1cAI):
package main

import "unsafe"
import "fmt"

type LibArray uintptr

func LibFunc(p LibArray) {

    fmt.Println(*(*uint16)(unsafe.Pointer(p)))
    fmt.Println(*(*uint16)(unsafe.Pointer(p + 2)))
}

func MakeLibArray() LibArray {

    array := []uint16{1, 2, 3, 4}
    return LibArray(unsafe.Pointer(&array[0]))
}

func main() {

    libArray := MakeLibArray()
    // At this point is there anything that keeps `array` from being garbage
    // collected?
    LibFunc(libArray)
}

Is it possible that *array *could get garbage collected before *LibFunc *is 
called, since the only live reference is the *uintptr*? There are some very 
old threads that seem to say that this worked at that time, but that the GC 
system would likely change in the future, making this dangerous.  

The example above demonstrates my question, though my actual use case is 
cgo, something more like: https://play.golang.org/p/1CqIgNjb11

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to