mirror of
https://github.com/SagerNet/sing-box.git
synced 2024-11-25 10:01:30 +00:00
Build memory limiter for android
This commit is contained in:
parent
1121517755
commit
69b5dbdcc3
|
@ -1,18 +1,22 @@
|
||||||
//go:build darwin
|
|
||||||
|
|
||||||
package libbox
|
package libbox
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"math"
|
||||||
runtimeDebug "runtime/debug"
|
runtimeDebug "runtime/debug"
|
||||||
|
|
||||||
"github.com/sagernet/sing-box/common/dialer/conntrack"
|
"github.com/sagernet/sing-box/common/dialer/conntrack"
|
||||||
)
|
)
|
||||||
|
|
||||||
const memoryLimit = 30 * 1024 * 1024
|
func SetMemoryLimit(enabled bool) {
|
||||||
|
const memoryLimit = 30 * 1024 * 1024
|
||||||
func SetMemoryLimit() {
|
if enabled {
|
||||||
runtimeDebug.SetGCPercent(10)
|
runtimeDebug.SetGCPercent(10)
|
||||||
runtimeDebug.SetMemoryLimit(memoryLimit)
|
runtimeDebug.SetMemoryLimit(memoryLimit)
|
||||||
conntrack.KillerEnabled = true
|
conntrack.KillerEnabled = true
|
||||||
conntrack.MemoryLimit = memoryLimit
|
conntrack.MemoryLimit = memoryLimit
|
||||||
|
} else {
|
||||||
|
runtimeDebug.SetGCPercent(100)
|
||||||
|
runtimeDebug.SetMemoryLimit(math.MaxInt64)
|
||||||
|
conntrack.KillerEnabled = false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue