Memory Leak Demo : New « Class Definition « Java Tutorial






class List {
  MemoryLeak mem;
  List next;
}

class MemoryLeak {
  static List top;

  char[] memory = new char[100000];

  public static void main(String[] args) {
    for (int i = 0; i < 100000; i++) {
      List temp = new List();
      temp.mem = new MemoryLeak();
      temp.next = top;
      top = temp;
    }
  }
}








5.20.New
5.20.1.Creating Objects
5.20.2.Memory Leak Demo