FAQ
Test environment
window 32 x86 go 1.0.3

Test Code:

package main

import (

"fmt"

"os"

"time"

)

func main() {

c := time.Tick(20 * time.Millisecond)

for _ = range c {

test()

}

}

func test() {

file, err := os.Create("e:\\test.txt")

if err != nil {

fmt.Println("=========")

}
//There is no leak

db := make([]byte, 10000000)

file.Write(db)

db = make([]byte, 10000000)

file.Write(db)

db = make([]byte, 10000000)

file.Write(db)

db = make([]byte, 10000000)

file.Write(db)

db = make([]byte, 10000000)

file.Write(db)


//Memory leak

//db := make([]byte, 50000000)

//file.Write(db)

file.Close()

}

--

Search Discussions

  • Rob Lapensee at Oct 22, 2012 at 11:33 am
    ni hao Cao Yin,

    I could not re-create this as a problem.

    $ go version
    go version go1.0.3

    from go env:
    GOARCH=386
    GOHOSTARCH=386
    GOHOSTOS=windows

    after 1 minute it got to 170m of memory used (from task manager)
    but then the memory usage graph flattened out
    my test ran for 20 minutes.

    you should be aware of issue 909
    do a google search on "issue 909 golang"

    Regards,

    Rob
    On Monday, October 22, 2012 5:50:49 AM UTC-4, 曹贤 wrote:

    Test environment
    window 32 x86 go 1.0.3

    Test Code:

    package main

    import (

    "fmt"

    "os"

    "time"

    )

    func main() {

    c := time.Tick(20 * time.Millisecond)

    for _ = range c {

    test()

    }

    }

    func test() {

    file, err := os.Create("e:\\test.txt")

    if err != nil {

    fmt.Println("=========")

    }
    //There is no leak

    db := make([]byte, 10000000)

    file.Write(db)

    db = make([]byte, 10000000)

    file.Write(db)

    db = make([]byte, 10000000)

    file.Write(db)

    db = make([]byte, 10000000)

    file.Write(db)

    db = make([]byte, 10000000)

    file.Write(db)


    //Memory leak

    //db := make([]byte, 50000000)

    //file.Write(db)

    file.Close()

    }
    --
  • Rob Lapensee at Oct 22, 2012 at 12:50 pm
    The new program does show the problem (this problem may be related to issue
    909)

    here is a simpler program that will re-create the problem:

    package main

    import "fmt"
    //import "runtime"

    func main() {
    for {
    fmt.Printf(".")
    x := make([]byte, 50000000)
    x[0] = 1 // to avoid "declared and not used"
    //runtime.GC()
    }
    }

    $ go run y.go
    ..............................runtime: out of memory: cannot allocate
    50003968-byte block (1101135872 in use)
    throw: out of memory

    goroutine 1 [running]:
    main.main()
    C:/temp/tmp04/y.go:9 +0x5f

    goroutine 2 [syscall]:
    created by runtime.main

    C:/Users/ADMINI~1/AppData/Local/Temp/2/bindist721200707/go/src/pkg/runtime/proc.c:221
    exit status 2

    it runs 30 iterations before failure.
    running on Windows XP (32 bit) with 2gb memory.
    go version 1.0.3.

    note by implementing the "GC" call I am getting inconsistent results.
    always running longer,
    sometimes crashing.
    it seems to consume some amount of memory,
    keeps that amount of memory for a few minutes,
    then consuming more memory,
    keeping that level for a few minutes,
    then crashing with out of memory.

    note: this does not seem to be a problem on 64 bit linux go version 1.0.3
    (with or without the GC call)

    Regards,

    Rob
    On Monday, October 22, 2012 7:33:33 AM UTC-4, Rob Lapensee wrote:

    ni hao Cao Yin,

    I could not re-create this as a problem.

    $ go version
    go version go1.0.3

    from go env:
    GOARCH=386
    GOHOSTARCH=386
    GOHOSTOS=windows

    after 1 minute it got to 170m of memory used (from task manager)
    but then the memory usage graph flattened out
    my test ran for 20 minutes.

    you should be aware of issue 909
    do a google search on "issue 909 golang"

    Regards,

    Rob
    On Monday, October 22, 2012 5:50:49 AM UTC-4, 曹贤 wrote:

    Test environment
    window 32 x86 go 1.0.3

    Test Code:

    package main

    import (

    "fmt"

    "os"

    "time"

    )

    func main() {

    c := time.Tick(20 * time.Millisecond)

    for _ = range c {

    test()

    }

    }

    func test() {

    file, err := os.Create("e:\\test.txt")

    if err != nil {

    fmt.Println("=========")

    }
    //There is no leak

    db := make([]byte, 10000000)

    file.Write(db)

    db = make([]byte, 10000000)

    file.Write(db)

    db = make([]byte, 10000000)

    file.Write(db)

    db = make([]byte, 10000000)

    file.Write(db)

    db = make([]byte, 10000000)

    file.Write(db)


    //Memory leak

    //db := make([]byte, 50000000)

    //file.Write(db)

    file.Close()

    }
    --

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedOct 22, '12 at 9:57a
activeOct 22, '12 at 12:50p
posts3
users2
websitegolang.org

2 users in discussion

Rob Lapensee: 2 posts 曹贤: 1 post

People

Translate

site design / logo © 2021 Grokbase