diff --git a/packages/core/src/Core.ts b/packages/core/src/Core.ts index d7d07317..47e38d16 100644 --- a/packages/core/src/Core.ts +++ b/packages/core/src/Core.ts @@ -165,8 +165,9 @@ export class Core { this._performanceMonitor.enable(); } - // 初始化对象池管理器(单例模式) - this._poolManager = PoolManager.getInstance(); + // 初始化对象池管理器 + this._poolManager = new PoolManager(); + this._serviceContainer.registerInstance(PoolManager, this._poolManager); // 初始化场景管理器 this._sceneManager = new SceneManager(); diff --git a/packages/core/src/Utils/Pool/PoolManager.ts b/packages/core/src/Utils/Pool/PoolManager.ts index 9fcb1933..6299e389 100644 --- a/packages/core/src/Utils/Pool/PoolManager.ts +++ b/packages/core/src/Utils/Pool/PoolManager.ts @@ -1,21 +1,18 @@ import { IPoolable, PoolStats } from './IPoolable'; import { Pool } from './Pool'; +import type { IService } from '../../Core/ServiceContainer'; /** * 池管理器 * 统一管理所有对象池 */ -export class PoolManager { - private static instance: PoolManager; +export class PoolManager implements IService { private pools = new Map>(); private autoCompactInterval = 60000; // 60秒 private lastCompactTime = 0; - public static getInstance(): PoolManager { - if (!PoolManager.instance) { - PoolManager.instance = new PoolManager(); - } - return PoolManager.instance; + constructor() { + // 普通构造函数,不再使用单例模式 } /** @@ -228,4 +225,12 @@ export class PoolManager { this.pools.clear(); this.lastCompactTime = 0; } + + /** + * 释放资源 + * 实现 IService 接口 + */ + public dispose(): void { + this.reset(); + } } \ No newline at end of file