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

内存泄漏的问题 复制重试却不一样的结果,求助! #81

Open
shcw opened this issue Apr 14, 2022 · 0 comments
Open

内存泄漏的问题 复制重试却不一样的结果,求助! #81

shcw opened this issue Apr 14, 2022 · 0 comments

Comments

@shcw
Copy link

shcw commented Apr 14, 2022

大佬,我看了这篇帖子 https://github.com/helios741/myblog/tree/new/learn_go/src/2021/08/go_feak_memory_lark 当我也想复现这个问题的时候出现了奇怪的情况,
image内存一直不下来。。。

go版本:1.17.8 环境centos7
执行代码如下

package main

import (
	"fmt"
	"github.com/prometheus/client_golang/prometheus"
	"github.com/prometheus/client_golang/prometheus/promhttp"
	log "github.com/sirupsen/logrus"
	"net/http"
	_ "net/http/pprof"
	"time"
)

func allocate(s int) {
	a := make([]byte, s*1024*1024)
	for i := 0; i < len(a); i += 4096 {
		a[i] = 'x'
	}
	fmt.Printf("alloc%c %d\n", a[0], s)
	a = nil
}

func main() {
	allocate(100)
	allocate(200)
	allocate(500)

	go func() {
		// Expose the registered metrics via HTTP.
		http.Handle("/metrics", promhttp.HandlerFor(
			prometheus.DefaultGatherer,
			promhttp.HandlerOpts{
				// Opt into OpenMetrics to support exemplars.
				EnableOpenMetrics: true,
			},
		))

		err := http.ListenAndServe(":8166", nil)
		if err != nil {
			log.Errorf("ListenAndServe: %+v", err)
		}
	}()

	time.Sleep(300 * time.Second)
}

希望大佬可以解答下

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