void () { List<T> toRemove = new ArrayList<>(); processAll(t -> toRemove.add(t)); for (T t : toRemove) { removeInterval(t); } l.writeLock().lock(); try { // make sure to avoid clearing when there are markers created between "removeInterval" and write lock start if (nodeSize() == 0) { super.clear(); keySize = 0; } } finally { l.writeLock().unlock(); } }