-
Notifications
You must be signed in to change notification settings - Fork 18.4k
Closed
Labels
Description
package main
import (
"bytes"
"fmt"
"io/ioutil"
"math/rand"
"runtime"
"time"
)
func main() {
for i := 0; i < 1000; i++ {
time.Sleep(time.Millisecond * 1)
go fakeGetAndSaveData()
}
runtime.GC()
time.Sleep(10 * time.Minute)
}
func fakeGetAndSaveData() {
var buf bytes.Buffer
for i := 0; i < 40000; i++ {
buf.WriteString(fmt.Sprintf("the number is %d\n", i))
}
ioutil.WriteFile(fmt.Sprintf("%d.txt", rand.Int()), buf.Bytes(), 0644)
}
Copied from issue #9869 .
Reporter thinks the memory used by this program is not returned to the OS during the Sleep(10*minute) call.
On Linux, I'm using top -b | grep memoryLeak command and on Windows, I use Task Manager. I just ran this again on Ubuntu 16.04 and it looks like it isn't exhibiting the problem after all. When I ran it yesterday it crashed my VM, but it wasn't due to out of memory as I'd assumed. But, I do see the problem clearly on Windows. Sorry, I'll put together a different example for Linux.
Here's what I see on Windows. This is after it's gone idle. Nothing new is being spawned. It's just sitting there. It stays like this for 10 minutes until the program closes.