Is this really working.? For me also the memory keeps growing ..i have a nested map structure though..only when the top level mao is gone i see memory shrinking. Just deleting entries from the top level map doesn't see to solve any issue,
On Tuesday, August 28, 2018 at 12:43:00 AM UTC+5:30, Kasun Vithanage wrote: > > thanks this answer will work > > On Monday, August 27, 2018 at 9:56:16 PM UTC+5:30, Jake Montgomery wrote: >> >> Just to be clear, the memory used by the values *are *freed. In your >> example, those are the Person structs. It is only the internal memory used >> by the map that is not freed. See https://play.golang.org/p/fWOIbvjFjyB. >> In that test, the "internal" memory that is not freed is about 14 bytes per >> entry. >> >> Of course, keep in mind that nothing is freed until a GC is done. >> >> On Monday, August 27, 2018 at 5:00:14 AM UTC-4, Kasun Vithanage wrote: >>> >>> I've a map which has set of keys and pointing to some structs like this. >>> In here i allocate lot of entries and trying to delete them. But the memory >>> usage is not shrinking. >>> >>> According to this issue <https://github.com/golang/go/issues/20135> it >>> seems how go behave at this point. In there its suggested to create a new >>> map and move all data there for reduced memory usage. But that seems not a >>> better option as it >>> is an expensive operation against such large map. >>> >>> What is the best way to delete a key from map freeing the memory >>> occupied by the Value(a pointer in this case). >>> >>> type Person struct { >>> Name string >>> } >>> >>> func NewPerson(name string) *Person { >>> return &Person{Name: name} >>> } >>> >>> func main() { >>> m := make(map[int]*Person) >>> >>> for i := 0; i < 1000000000; i++ { >>> m[i] = NewPerson("Person" + strconv.Itoa(i)) >>> } >>> >>> for index := 0; index < 10000; index++ { >>> m[index] = nil >>> delete(m, index) >>> } >>> } >>> >>> >>> >>> -- 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. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/dc7fe1d2-3980-4e6d-8769-b147e8c4f28b%40googlegroups.com.