* 压缩池(移除多余的对象) * @param targetSize 目标大小,默认为当前大小的一半
(targetSize?: number)
| 124 | * @param targetSize 目标大小,默认为当前大小的一半 |
| 125 | */ |
| 126 | public compact(targetSize?: number): void { |
| 127 | const target = targetSize ?? Math.floor(this._objects.length / 2); |
| 128 | |
| 129 | while (this._objects.length > target) { |
| 130 | const obj = this._objects.pop(); |
| 131 | if (obj) { |
| 132 | obj.reset(); |
| 133 | this._stats.size--; |
| 134 | } |
| 135 | } |
| 136 | |
| 137 | this._updateMemoryUsage(); |
| 138 | } |
| 139 | |
| 140 | /** |
| 141 | * 预填充池 |
no test coverage detected