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

cmd/compile: a slice captured by a closure might leak #48254

Closed
hajimehoshi opened this issue Sep 8, 2021 · 2 comments
Closed

cmd/compile: a slice captured by a closure might leak #48254

hajimehoshi opened this issue Sep 8, 2021 · 2 comments
Labels
FrozenDueToAge OS-Darwin WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.

Comments

@hajimehoshi
Copy link
Member

hajimehoshi commented Sep 8, 2021

What version of Go are you using (go version)?

$ go version
go version go1.17 darwin/amd64

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/hajimehoshi/Library/Caches/go-build"
GOENV="/Users/hajimehoshi/Library/Application Support/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/hajimehoshi/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/hajimehoshi/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GOVCS=""
GOVERSION="go1.17"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/hajimehoshi/test/go.mod"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -arch x86_64 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/60/khbk2xqn1c5bml1byjn89dwc0000gn/T/go-build3631899530=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

Run this and see the memory usage (I saw "Real Private Memory" on Activity on macOS):

package main

import (
        "time"
        "runtime"
)

var f func()

func foo(bs []byte) {
        if f == nil {
                copied := make([]byte, len(bs))
                copy(copied, bs)
                f = func() {
                        foo(copied)
                }
                return
        }

        println(len(bs))
}

func main() {
        bs := make([]byte, 100*1024*1024)
        foo(bs)

        f()
        f = nil
        bs = nil

        for {
                runtime.GC()
                time.Sleep(time.Second)
        }
}

What did you expect to see?

The private memory usage should be the same as this program (less than 10[MB] maybe):

func main() {
        for {
                runtime.GC()
                time.Sleep(time.Second)
        }
}

What did you see instead?

The private memory usage keeps about 200[MB]

@randall77
Copy link
Contributor

Seems ok to me:

% top -ncols 8 | grep issue48254
76731  issue48254       0.0  00:00.19 7      0   16+    208M+ 
76731  issue48254       2.2  00:00.21 8      0   17+    203M- 
76731  issue48254       4.5  00:00.26 8      0   17     192M- 
76731  issue48254       4.5  00:00.30 8      0   17     182M- 
76731  issue48254       4.5  00:00.35 8      0   17     171M- 
76731  issue48254       4.4  00:00.40 8      0   17     160M- 
76731  issue48254       4.4  00:00.44 8/1    0   17     149M- 
76731  issue48254       4.5  00:00.50 8      0   17     138M- 
76731  issue48254       4.4  00:00.54 8      0   17     128M- 
76731  issue48254       4.4  00:00.59 8      0   17     118M- 
76731  issue48254       4.5  00:00.64 8      0   17     107M- 
76731  issue48254       6.3  00:00.70 8      0   17     88M-  
76731  issue48254       5.7  00:00.76 8      0   17     71M-  
76731  issue48254       4.7  00:00.81 8      0   17     60M-  
76731  issue48254       4.7  00:00.86 8      0   17     48M-  
76731  issue48254       4.7  00:00.91 8      0   17     37M-  
76731  issue48254       4.7  00:00.96 8      0   17     26M-  
76731  issue48254       4.7  00:01.02 8      0   17     12M-  
76731  issue48254       1.5  00:01.03 8      0   17     8480K-
76731  issue48254       0.0  00:01.03 8      0   17     8512K+
76731  issue48254       0.1  00:01.03 8      0   17     8416K-
76731  issue48254       0.0  00:01.04 8      0   17     8416K 

I see the same memory reduction pattern when using Activity Monitor.

@randall77 randall77 added WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. OS-Darwin labels Sep 8, 2021
@hajimehoshi
Copy link
Member Author

Ah OK, I didn't realized the memory usage is decreased gradually... Thanks!

@golang golang locked and limited conversation to collaborators Sep 8, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge OS-Darwin WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Projects
None yet
Development

No branches or pull requests

3 participants