Memory Management in Tensor Flow

Overview


Tensors created in Tensor Flow js are not subject to the standard memory management that applies to normal Javascript. When a tensor is declared, memory is allocated to that tensor which needs to be manually released.

To deallocate an object, just call the dispose method on the object

tensor.dispose()
				
Try it!

Tidy


The tensor flow library includes a method called tidy, that will deallocate all non returned objects created within. That is, any objects created within the function passed to tidy will be de-allocated after the call completes.

tf.tidy(() => {
	//do something							
});