* Dispose the memory if the dataId has 0 refCount. Return true if the memory * is released, false otherwise. * @param dataId * @oaram force Optional, remove the data regardless of refCount
(dataId: DataId, force = false)
| 238 | * @oaram force Optional, remove the data regardless of refCount |
| 239 | */ |
| 240 | disposeData(dataId: DataId, force = false): boolean { |
| 241 | // No-op if already disposed. |
| 242 | if (this.tensorMap.has(dataId)) { |
| 243 | const id = this.tensorMap.get(dataId).id; |
| 244 | this.tensorMap.get(dataId).refCount--; |
| 245 | if (!force && this.tensorMap.get(dataId).refCount > 0) { |
| 246 | return false; |
| 247 | } |
| 248 | |
| 249 | if (id != null && id >= 0) { |
| 250 | this.binding.deleteTensor(id); |
| 251 | } |
| 252 | this.tensorMap.delete(dataId); |
| 253 | } |
| 254 | return true; |
| 255 | } |
| 256 | /** Return refCount of a `TensorData`. */ |
| 257 | refCount(dataId: DataId): number { |
| 258 | if (this.tensorMap.has(dataId)) { |
nothing calls this directly
no test coverage detected