有没有办法知道谁持有对Go中对象的引用?

I am currently trying to debug a nasty memory leak in our Go code.

What I know:

  • where memory is going (pprof with -base flag)
  • why new memory is being allocated ("reconnect" feature in our code)
  • number of goroutines is not growing (runtime.NumGoroutine())
  • if I do object = nil, memory will be garbage collected (good! but now I have data races with other go-routines that are using this object)

What I don't know:

  • why new memory is not being garbage collected. for that I need to know who holds a reference(s) to an object.

Thank you for your time and any advice!

Your code is 404 not found.

When you put object = nil. this did not be cleared immediately however when some goroutine still holds it , the object will keep still even if gc runs.

You ask who hold the reference, goroutine who uses this val without put it to nil or the goroutine uses it in a loop will both keep the reference.

The gc() will never marked a referred reference to black, then it will never be clear