title: Need help to understand garbage collection in GoLang
body: <p>I'm a little bit confused with GoLang's garbage collector.</p>
  
  <p>Consider this following code, where I implement reader interface for my type T.</p>
  
  <pre><code>type T struct {
     header Header
     data   []*MyDataType
  }
  
  func (t *T) Read(p []byte) (int, error) {
      t.Header = *(*Header) (t.readFileHeader(p))
      t.Data = *(*[]*MyDataType) (t.readFileData(p))
  }
  </code></pre>
  
  <p>wherein the reader functions I will cast the data to MyDataType using the <code>unsafe.Pointer</code> which will point to slice created with the reflect module (this is more complicated, but for the sake of the example this should be enough)</p>
  
  <pre><code>func (t *T) readFileData(data []byte, idx int, ...) unsafe.Pointer {
      ...
      return unsafe.Pointer(&amp;reflect.SliceHeader{Data : uintptr(unsafe.Pointer(&amp;data[idx])), ...}) 
  }
  </code></pre>
  
  <p>and If I am gonna read the data in different function</p>
  
  <pre><code>func (d *Dummy) foo() {
      data, _ := ioutil.ReadFile(filename)
      d.t.Read(data) &lt;---will GC free data?
  }
  </code></pre>
  
  <p>Now I'm confused if it is possible, that the GC will free loaded data from file after exiting the <code>foo</code> function. Or the data will be freed after the <code>d.t</code> is freed.</p>