From 14a8d755f0207effd818d056da86a3b5bb34847b Mon Sep 17 00:00:00 2001 From: YHH <359807859@qq.com> Date: Sat, 11 Oct 2025 09:38:16 +0800 Subject: [PATCH] =?UTF-8?q?PoolManager=20=E7=8E=B0=E5=9C=A8=E7=94=B1=20Ser?= =?UTF-8?q?viceContainer=20=E7=BB=9F=E4=B8=80=E7=AE=A1=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/core/src/Core.ts | 5 +++-- packages/core/src/Utils/Pool/PoolManager.ts | 19 ++++++++++++------- 2 files changed, 15 insertions(+), 9 deletions(-) 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