code: def num_in_memory(self):
      
      n = len(self._data) - 1
      while n >= 0:
        if isinstance(self._data[n], _TensorValueDiscarded):
          break
        n -= 1
      return len(self._data) - 1 - n
docs: Get number of values in memory.