mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-10 09:11:55 +00:00
FIX: fix memory leak
This commit is contained in:
parent
50262f2a84
commit
0e68cb1f7e
|
@ -5,6 +5,8 @@ import "github.com/c9s/bbgo/pkg/types"
|
|||
const MaxNumOfKLines = 5_000
|
||||
const MaxNumOfKLinesTruncate = 100
|
||||
|
||||
const CapacityOfKLineWindowLimit = 5_000
|
||||
|
||||
// MarketDataStore receives and maintain the public market data of a single symbol
|
||||
//go:generate callbackgen -type MarketDataStore
|
||||
type MarketDataStore struct {
|
||||
|
@ -57,8 +59,13 @@ func (store *MarketDataStore) AddKLine(k types.KLine) {
|
|||
}
|
||||
window.Add(k)
|
||||
|
||||
if len(*window) > MaxNumOfKLines {
|
||||
*window = (*window)[MaxNumOfKLinesTruncate-1:]
|
||||
lenOfWindow := len(*window)
|
||||
capOfWindow := cap(*window)
|
||||
|
||||
if lenOfWindow == capOfWindow && capOfWindow > CapacityOfKLineWindowLimit {
|
||||
truncatedWindow := (*window)[(CapacityOfKLineWindowLimit / 2):]
|
||||
copy(*window, truncatedWindow)
|
||||
*window = (*window)[:len(truncatedWindow)]
|
||||
}
|
||||
|
||||
store.EmitKLineClosed(k)
|
||||
|
|
Loading…
Reference in New Issue
Block a user