November 2019
Intermediate to advanced
296 pages
7h 52m
English
While the JavaScript runtime has a mechanism for garbage collection, the GPU that's used by WebGL doesn't. This means that no process can automatically free the memory space that's allocated by tensors. Going out of the scope of the tensor is not sufficient if we wish to release the memory that's been allocated for tensors. To destroy the tensor, including its memory, we need to call the dispose method of the tensor itself:
console.log(tf.memory()); // -> {unreliable: false, numBytesInGPU: 0, numTensors: 0, numDataBuffers: 0, numBytes: 0}const a = tf.tensor([1, 2, 3]);console.log(tf.memory()); // -> {unreliable: false, numBytesInGPU: 0, numTensors: 1, numDataBuffers: 1, numBytes: 12}a.dispose();console.log(tf.memory()); // -> {unreliable: ...Read now
Unlock full access