Add ios memory limit

This commit is contained in:
世界 2023-03-02 13:13:12 +08:00
parent e8802357e1
commit 8151bcfd6b
No known key found for this signature in database
GPG key ID: CD109927C34A63C4
3 changed files with 12 additions and 4 deletions

View file

@ -86,10 +86,10 @@ func buildiOS() {
if !debugEnabled { if !debugEnabled {
args = append( args = append(
args, "-trimpath", "-ldflags=-s -w -buildid=", args, "-trimpath", "-ldflags=-s -w -buildid=",
"-tags", "with_gvisor,with_quic,with_wireguard,with_utls,with_clash_api", "-tags", "with_gvisor,with_utls,with_clash_api",
) )
} else { } else {
args = append(args, "-tags", "with_gvisor,with_quic,with_wireguard,with_utls,with_clash_api,debug") args = append(args, "-tags", "with_gvisor,with_utls,with_clash_api,debug")
} }
args = append(args, "./experimental/libbox") args = append(args, "./experimental/libbox")
@ -102,7 +102,7 @@ func buildiOS() {
log.Fatal(err) log.Fatal(err)
} }
copyPath := filepath.Join("..", "sfi") copyPath := filepath.Join("..", "sing-box-for-ios")
if rw.FileExists(copyPath) { if rw.FileExists(copyPath) {
targetDir := filepath.Join(copyPath, "Libbox.xcframework") targetDir := filepath.Join(copyPath, "Libbox.xcframework")
targetDir, _ = filepath.Abs(targetDir) targetDir, _ = filepath.Abs(targetDir)

View file

@ -20,7 +20,7 @@ func readStatus() StatusMessage {
var memStats runtime.MemStats var memStats runtime.MemStats
runtime.ReadMemStats(&memStats) runtime.ReadMemStats(&memStats)
var message StatusMessage var message StatusMessage
message.Memory = int64(memStats.HeapInuse + memStats.StackInuse + memStats.MSpanInuse) message.Memory = int64(memStats.Sys - memStats.HeapReleased)
message.Goroutines = int32(runtime.NumGoroutine()) message.Goroutines = int32(runtime.NumGoroutine())
return message return message
} }

View file

@ -0,0 +1,8 @@
package libbox
import "runtime/debug"
func SetMemoryLimit() {
debug.SetGCPercent(10)
debug.SetMemoryLimit(30 * 1024 * 1024)
}