Comments (3)
Thanks guys, I have done some experiments after your questions, I think this channel is useless, you can reproduce the result by following demo:
package main
import (
"runtime"
"time"
)
type finalizer struct {
ref *finalizerRef
}
type finalizerRef struct {
parent *finalizer
}
// default GOGC = 100
var previousGOGC = 100
// don't trigger err log on every failure
var failCounter = -1
func finalizerHandler(f *finalizerRef) {
println("in final handler")
runtime.SetFinalizer(f, finalizerHandler)
}
type person struct {
data []byte
}
// NewTuner
// set useCgroup to true if your app is in docker
// set percent to control the gc trigger, 0-100, 100 or upper means no limit
//
// modify default GOGC value in the case there's an env variable set.
func getFinal() * finalizer {
var f = &finalizer{
}
f.ref = &finalizerRef{parent: f}
runtime.SetFinalizer(f.ref, finalizerHandler)
f.ref = nil
return f
}
func main() {
f := getFinal()
println(f)
for {
var x = person{make([]byte, 100000)}
time.Sleep(time.Millisecond*40)
println(x.data[0])
}
}
GODEBUG=gctrace=1 go run ./tuner.go
you should see every gc trigger will print a line of 'in final handler'
from gogctuner.
Avoid finalizer being collected by GC? why use chan time.Time?
the original code is from uber's blog article, I think any struct is ok~
from gogctuner.
can it just simply be runtime.KeepAlive(f.parent)
or just be empty (do nothing)?
from gogctuner.
Related Issues (6)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from gogctuner.