* 从池中获取对象 * @returns 对象实例
()
| 61 | * @returns 对象实例 |
| 62 | */ |
| 63 | public obtain(): T { |
| 64 | this._stats.totalObtained++; |
| 65 | |
| 66 | if (this._objects.length > 0) { |
| 67 | const obj = this._objects.pop()!; |
| 68 | this._stats.size--; |
| 69 | this._updateHitRate(); |
| 70 | this._updateMemoryUsage(); |
| 71 | return obj; |
| 72 | } |
| 73 | |
| 74 | // 池中没有可用对象,创建新对象 |
| 75 | this._stats.totalCreated++; |
| 76 | this._updateHitRate(); |
| 77 | return this._createFn(); |
| 78 | } |
| 79 | |
| 80 | /** |
| 81 | * 释放对象回池中 |
no test coverage detected