import tensorflow as tf

                ref=self.episode_indices[-1],
                value=tf.where(self.memory_index + num_instances > self.capacity,
                               self.episode_indices[self.episode_count - 1], self.capacity - 1)
            )

        with tf.control_dependencies(control_inputs=(assignment,)):
            assignment = tf.assign(ref=self.memory_index, value=((self.memory_index + num_instances) % self.capacity))

        with tf.control_dependencies(control_inputs=(assignment,)):
            return tf.no_op()

    def tf_retrieve_indices(self, indices):
        """
        Fetches experiences for given indices.

        Args:
