daemon: Release memory to OS on service reload

This commit is contained in:
世界
2026-07-07 19:09:50 +08:00
parent f2dd4bfd75
commit f617dc42aa
+4 -2
View File
@@ -4,6 +4,7 @@ import (
"context"
"os"
"runtime"
runtimeDebug "runtime/debug"
"sync"
"time"
@@ -190,6 +191,7 @@ func (s *StartedService) StartOrReloadService(profileContent string, options *Ov
s.updateStatus(ServiceStatus_STOPPING)
s.serviceAccess.Unlock()
_ = oldInstance.Close()
runtimeDebug.FreeOSMemory()
s.serviceAccess.Lock()
}
s.updateStatus(ServiceStatus_STARTING)
@@ -216,7 +218,7 @@ func (s *StartedService) StartOrReloadService(profileContent string, options *Ov
s.startedAt = time.Now()
s.updateStatus(ServiceStatus_STARTED)
s.serviceAccess.Unlock()
runtime.GC()
runtimeDebug.FreeOSMemory()
return nil
}
@@ -247,7 +249,7 @@ func (s *StartedService) CloseService() error {
s.startedAt = time.Time{}
s.updateStatus(ServiceStatus_IDLE)
s.serviceAccess.Unlock()
runtime.GC()
runtimeDebug.FreeOSMemory()
return nil
}