An traditional way:
// Clear all elements by iterating
var next *Element
for e := l.Front(); e != nil; e = next {
next = e.Next()
l.Remove(e)
}
How about using:
l.Init()
Is it a safe way that will not causing any memory leak?
From http://golang.org/pkg/container/list/#List.Init
Init initializes or clears list l.
A side note, a slice is probably better for most usage scenarios, check Slice Tricks.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With