<pre class="notranslate">The Go core packages should never leak memory.

container/list.Iter() leaks memory when the channel is not drained.

6g; hg id ec584ae2ad58 tip; GOOS=linux; GOARCH=amd64.

package main

import (
    "fmt"
    "container/list"
    "runtime"
)

func memleak() {
    l := list.New()
    for i := 0; i &lt; 1e3; i++ {
        l.PushBack(make([]byte, 1e6))
    }
    for _ = range l.Iter() {
        break
    }
    l.Init()
}

func main() {
    for i := 0; i &lt; 10; i++ {
        memleak()
        runtime.GC()
        fmt.Println(i, runtime.MemStats.Alloc, runtime.MemStats.TotalAlloc)
    }
}

Output:
0 1073420608 1073434744
1 2146666592 2146680728
2 3219910416 3219924600
3 4293155776 4293170008
4 5366401136 5366415416
5 6439644960 6439659288
6 7512890320 7512904696
7 8586135680 8586150104
8 9659379504 9659393976
9 10732624864 10732639384

Problems with a memory-leaking tree structure - golang-nuts
<a href="http://groups.google.com/group/golang-nuts/browse_thread/thread/371c577eb7a5cad6/72e40e8588341c3c" rel="nofollow">http://groups.google.com/group/golang-nuts/browse_thread/thread/371c577eb7a5cad6/72e40e8588341c3c</a></pre>
<p dir="auto">We need to document what the rules are.</p>