resetAndClear method

void resetAndClear(
  1. T empty
)

Reset the circular buffer to the empty state, and clear out the old elements from the underlying storage by filling it with empty. Usually this isn't necessary, because those elements are inaccessible, but not clearing them makes the inelilgible for GC, until those positions are overwritten.

Implementation

void resetAndClear(T empty) {
  for (int i = 0; i < length; i++) {
    this[i] = empty;
  }
  reset();
}