<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def num_in_memory(self):
 """Get number of values in memory."""

    n = len(self._data) - 1
    while n >= 0:
      if isinstance(self._data[n], _TensorValueDiscarded):
        break
      n -= 1
    return len(self._data) - 1 - n