void () { int toSaveAlive = 0; for (int i=0; i<myList.size();i++) { MyReference<T> reference = myList.get(i); if (reference == null) continue; T t = reference.get(); if (t == null) { myAlive--; continue; } if (toSaveAlive != i) { myList.set(toSaveAlive, new MyReference<>(toSaveAlive, t, myQueue)); } toSaveAlive++; } if (toSaveAlive != myList.size()) { myList.subList(toSaveAlive, myList.size()).clear(); modCount++; } myAlive = toSaveAlive; }