import java.lang.management.ManagementFactory;

public class DemoLeak {

	static class Node {
		public Node next;
	}

	private static Node[] root;

	public static void main(String[] args) throws InterruptedException {
		int width = Integer.parseInt(args[0]);
		long depth = Long.parseLong(args[1]);
		System.out.println("Width: " + width);
		System.out.println("Height: " + depth);
		root = new Node[width];
		for (int i = 0; i < root.length; i++) {
			root[i] = new Node();
			Node lastNode = root[i];
			for (int j = 0; j < depth; j++) {
				lastNode.next = new Node();
				lastNode = lastNode.next;
			}
		}
		System.out.println("Allocated");
		System.gc();
		double used = ManagementFactory.getMemoryMXBean().getHeapMemoryUsage().getUsed();
		System.out.println("Used: " + used / (1024*1024));
		Thread.sleep(1_000_000_00);
	}
}
