Understanding Java ArrayList subList() Pitfalls and Safe Usage
Memory Leak Caused by subList
A common mistake with subList() is inadvertently retaining a reference to the original large list, leading to an OutOfMemoryError. Consider this example:
@Slf4j
public class SubListDemo {
public static void subListOOM() {
List<List<Integer>> data = new ArrayList<>();
for (int ...
Posted on Sat, 09 May 2026 05:39:15 +0000 by jstone3503