Memory leak fixes and optimisations.

This commit is contained in:
2025-08-28 09:59:47 +01:00
parent c878784f1e
commit e2e2be53c1
6 changed files with 342 additions and 43 deletions
+16
View File
@@ -217,6 +217,7 @@ func (p *TokenCompressionPool) PutStringBuilder(sb *strings.Builder) {
// Global memory pool manager instance
var globalMemoryPools *MemoryPoolManager
var memoryPoolOnce sync.Once
var memoryPoolMutex sync.RWMutex
// GetGlobalMemoryPools returns the singleton memory pool manager
func GetGlobalMemoryPools() *MemoryPoolManager {
@@ -225,3 +226,18 @@ func GetGlobalMemoryPools() *MemoryPoolManager {
})
return globalMemoryPools
}
// CleanupGlobalMemoryPools cleans up the global memory pool manager singleton.
// This should be called during application shutdown to prevent memory leaks.
// It's safe to call multiple times.
func CleanupGlobalMemoryPools() {
memoryPoolMutex.Lock()
defer memoryPoolMutex.Unlock()
if globalMemoryPools != nil {
// Clear the pools to release any pooled objects
globalMemoryPools = nil
// Reset the once to allow re-initialization if needed
memoryPoolOnce = sync.Once{}
}
}