Java “for” statement implementation prevents garbage collecting
问题 UPD 21.11.2017: the bug is fixed in JDK, see comment from Vicente Romero Summary: If for statement is used for any Iterable implementation the collection will remain in the heap memory till the end of current scope (method, statement body) and won't be garbage collected even if you don't have any other references to the collection and the application needs to allocate a new memory. http://bugs.java.com/bugdatabase/view_bug.do?bug_id=JDK-8175883 https://bugs.openjdk.java.net/browse/JDK-8175883