mirror of
https://github.com/amnezia-vpn/amnezia-libxray.git
synced 2026-05-17 06:55:44 +03:00
25 lines
381 B
Go
25 lines
381 B
Go
package nodep
|
|
|
|
import (
|
|
"runtime/debug"
|
|
"time"
|
|
)
|
|
|
|
func forceFree(interval time.Duration) {
|
|
go func() {
|
|
for {
|
|
time.Sleep(interval)
|
|
debug.FreeOSMemory()
|
|
}
|
|
}()
|
|
}
|
|
|
|
func InitForceFree(maxMemory int64, interval int) {
|
|
debug.SetGCPercent(10)
|
|
debug.SetMemoryLimit(maxMemory)
|
|
if interval > 0 {
|
|
duration := time.Duration(interval) * time.Second
|
|
forceFree(duration)
|
|
}
|
|
}
|