PoolManager 现在由 ServiceContainer 统一管理

This commit is contained in:
YHH
2025-10-11 09:38:16 +08:00
parent b67ab80c75
commit 14a8d755f0
2 changed files with 15 additions and 9 deletions

View File

@@ -165,8 +165,9 @@ export class Core {
this._performanceMonitor.enable(); this._performanceMonitor.enable();
} }
// 初始化对象池管理器(单例模式) // 初始化对象池管理器
this._poolManager = PoolManager.getInstance(); this._poolManager = new PoolManager();
this._serviceContainer.registerInstance(PoolManager, this._poolManager);
// 初始化场景管理器 // 初始化场景管理器
this._sceneManager = new SceneManager(); this._sceneManager = new SceneManager();

View File

@@ -1,21 +1,18 @@
import { IPoolable, PoolStats } from './IPoolable'; import { IPoolable, PoolStats } from './IPoolable';
import { Pool } from './Pool'; import { Pool } from './Pool';
import type { IService } from '../../Core/ServiceContainer';
/** /**
* 池管理器 * 池管理器
* 统一管理所有对象池 * 统一管理所有对象池
*/ */
export class PoolManager { export class PoolManager implements IService {
private static instance: PoolManager;
private pools = new Map<string, Pool<any>>(); private pools = new Map<string, Pool<any>>();
private autoCompactInterval = 60000; // 60秒 private autoCompactInterval = 60000; // 60秒
private lastCompactTime = 0; private lastCompactTime = 0;
public static getInstance(): PoolManager { constructor() {
if (!PoolManager.instance) { // 普通构造函数,不再使用单例模式
PoolManager.instance = new PoolManager();
}
return PoolManager.instance;
} }
/** /**
@@ -228,4 +225,12 @@ export class PoolManager {
this.pools.clear(); this.pools.clear();
this.lastCompactTime = 0; this.lastCompactTime = 0;
} }
/**
* 释放资源
* 实现 IService 接口
*/
public dispose(): void {
this.reset();
}
} }