* robert engels <reng...@ix.netcom.com> [240826 12:24]: > But why would you want to allocate a new array? This would only be required > if the MongoDB call were async, and the array cannot be reused. > > If you keep allocating new arrays you are putting needless pressure on the GC. >
True. But I was going on the assumption that the amount of memory allocated for the 10001 interface values, each holding 50000 records, swamped the memory used by the slice's backing array. Marking all of the interface values for collection before going back for another time through the loop was my goal. Since mongo.WriteModel is an interface, the memory for each element of model (the interface value) is kept until that element is overwritten, even when you have done «model = model[:0]». The OP can mark each of those elements to be garbage collected and at the same time avoid reallocating the slice's backing array by assigning nil to each element, and then reslicing model: for i := range(len(model)) { model[i] = nil } model = model[:0] ...Marvin -- 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/Zsy1BqMsb4Z9ytgB%40basil.wdw.