Hi Enrico, In the new ledger api, we return Iterable<LedgerEntry> instead of Iterator<LedgerEntry>. In general, it is good to return Iterable, however it seems to be problematic in following use case:
Iterable<LedgerEntry> entries = rh.read(...); Iterator<LedgerEntry> iter1 = entries.iterator(); while (iter1.hasNext()) { LedgerEntry le = iter1.next; le.getEntryBuffer().release(); } Iterator<LedgerEntry> iter2 = entries.iterator(); while (iter2.hasNext()) { LedgerEntry le = iter2.next(); le.getEntryBuffer().release(); } Using Iterable opens up the chance that people will create multiple iterators and use them concurrently. I think we should not use Iterable<LedgerEntry>, which it might actually cause problems. I am thinking if we can create an interface LedgerEntries to extend Iterable<LedgerEntry>. so: - the implementation can create increase right buffer reference when creating an iterator - we can make LedgerEntries a recycleable object, and it is returned to the tool when people called #close() - on #close(), it releases all the references to release resources interface LedgerEntries extends Iterable<LedgerEntry>, AutoCloseable { long getEntry(long entryId); Iterator<LedgerEntry> iterator(); }