Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

貌似有内存泄露呀 #32

Open
w22gb8 opened this issue Jan 7, 2015 · 0 comments
Open

貌似有内存泄露呀 #32

w22gb8 opened this issue Jan 7, 2015 · 0 comments

Comments

@w22gb8
Copy link

w22gb8 commented Jan 7, 2015

多次请求通过top能发现RES占用内存轻微持续上升,go1.4,linux 64,代码如下:
package main

import (
"fmt"
curl "github.com/andelf/go-curl"
)

func main() {
fooTest := func(buf []byte, userdata interface{}) bool {
//println("DEBUG: size=>", len(buf))
//println("DEBUG: content=>", string(buf))
return true
}
easy := curl.EasyInit()
defer easy.Cleanup()
for i := 0; i < 1000000; i++ {
easy.Setopt(curl.OPT_URL, "http://192.168.1.3/")
easy.Setopt(curl.OPT_WRITEFUNCTION, fooTest)
if err := easy.Perform(); err != nil {
fmt.Printf("ERROR: %v\n", err)
}
}
}
协程下同样如此:
package main

import (
"fmt"
curl "github.com/andelf/go-curl"
"sync"
)

func main() {
var wg sync.WaitGroup
var limit = make(chan struct{}, 200)
fooTest := func(buf []byte, userdata interface{}) bool {
//println("DEBUG: size=>", len(buf))
//println("DEBUG: content=>", string(buf))
return true
}
for i := 0; i < 1000000; i++ {
limit <- struct{}{}
wg.Add(1)
go func() {
easy := curl.EasyInit()
defer easy.Cleanup()
easy.Setopt(curl.OPT_URL, "http://192.168.1.3/")
easy.Setopt(curl.OPT_WRITEFUNCTION, fooTest)

        if err := easy.Perform(); err != nil {
            fmt.Printf("ERROR: %v\n", err)
        }
        <-limit
        defer wg.Done()
    }()
    wg.Wait()
}

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant