go - golang map value returned by value or reference? -


this question has answer here:

let's have map key of string , value of pointer struct

type entity struct{} entity := &entity{} m := map[string]*entity{"foo":entity} 

i value , delete entry later

en := m["foo"] delete(m, "foo") 

my question memory garbage collected since pointer removed map? on other note, have new pointer en before delete entry, it's copy of pointer points same memory location, memory not garbage collected map entry deleted? confused, appreciated.

go's current implementation parallel mark-and-sweep garbage collector.

to precise on scope entity declared, object won't garbaged collected, same reason mentioned - after deletion map there still reference object.

the state of map internal, , removed there after deletion operation.


Comments

Popular posts from this blog

python - Selenium remoteWebDriver (& SauceLabs) Firefox moseMoveTo action exception -

html - How to custom Bootstrap grid height? -

transpose - Maple isnt executing function but prints function term -