Browse Source

Add ios memory limit

世界 2 years ago
parent
commit
8151bcfd6b

+ 3 - 3
cmd/internal/build_libbox/main.go

@@ -86,10 +86,10 @@ func buildiOS() {
 	if !debugEnabled {
 		args = append(
 			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 {
-		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")
@@ -102,7 +102,7 @@ func buildiOS() {
 		log.Fatal(err)
 	}
 
-	copyPath := filepath.Join("..", "sfi")
+	copyPath := filepath.Join("..", "sing-box-for-ios")
 	if rw.FileExists(copyPath) {
 		targetDir := filepath.Join(copyPath, "Libbox.xcframework")
 		targetDir, _ = filepath.Abs(targetDir)

+ 1 - 1
experimental/libbox/command_status.go

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

+ 8 - 0
experimental/libbox/memory.go

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