转载自:https://blog.csdn.net/m0_46311226/article/details/104996664
import java.util.ArrayList; public class TestOOM { static class OOMObject { private String content; public OOMObject(String content){ this.content = content; } } public static void main(String[] args) { ArrayList<OOMObject> list = new ArrayList<>(); int i = 0; while(true){ list.add(new OOMObject(i+++"")); } } }