Comments (3)
I see, thank you for looking into this. I am pretty sure that I've seen this kind of code produce memory leaks in the past, but that was a while ago and since then the GC has been replaced. I agree this is a non-issue.
from bandchain.
bandchain/chain/x/oracle/abci.go
Line 14 in 6881433
from bandchain.
I don't think this is an issue. With the way the code is written, rollingSeed
's length is always 32. So the slice's cap should never go beyond ~64, and when a new array is allocated, the old array should get freed. Wrote a small POC program to ensure that allocated memory stays constant (despite total alloc keeps growing).
package main
import (
"fmt"
"runtime"
"time"
)
func main() {
slice := make([]byte, 32)
for i := 0; i < 1000000; i++ {
slice = append(slice[1:], byte(42))
if i%100000 == 0 {
runtime.GC()
PrintMemUsage()
time.Sleep(time.Second)
}
}
}
func PrintMemUsage() {
var m runtime.MemStats
runtime.ReadMemStats(&m)
// For info on each, see: https://golang.org/pkg/runtime/#MemStats
fmt.Printf("Alloc = %v kB", bToKb(m.Alloc))
fmt.Printf("\tTotalAlloc = %v kB", bToKb(m.TotalAlloc))
fmt.Printf("\tSys = %v kB", bToKb(m.Sys))
fmt.Printf("\tNumGC = %v\n", m.NumGC)
}
func bToKb(b uint64) uint64 {
return b / 1024
}
Output:
Alloc = 66 kB TotalAlloc = 79 kB Sys = 68610 kB NumGC = 1
Alloc = 67 kB TotalAlloc = 270 kB Sys = 68674 kB NumGC = 2
Alloc = 68 kB TotalAlloc = 461 kB Sys = 68674 kB NumGC = 3
Alloc = 68 kB TotalAlloc = 651 kB Sys = 68674 kB NumGC = 4
Alloc = 68 kB TotalAlloc = 841 kB Sys = 68674 kB NumGC = 5
Alloc = 68 kB TotalAlloc = 1031 kB Sys = 68674 kB NumGC = 6
Alloc = 68 kB TotalAlloc = 1221 kB Sys = 68674 kB NumGC = 7
Alloc = 68 kB TotalAlloc = 1411 kB Sys = 68674 kB NumGC = 8
Alloc = 68 kB TotalAlloc = 1601 kB Sys = 68674 kB NumGC = 9
Alloc = 68 kB TotalAlloc = 1791 kB Sys = 68674 kB NumGC = 10
from bandchain.
Related Issues (2)
- Incorrect Module Order HOT 1
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 bandchain.