Return to Snippet

Revision: 64522
at August 17, 2013 06:53 by rnavanee

Initial Code
import java.util.ArrayList;
import java.util.List;

public class JavaOOM {

	public static void main(String[] args) {
		System.out.println("Initial freeMemory: "+Runtime.getRuntime().freeMemory()/(1024*1024));

	private static void oom1() {
		List<String> myList = new ArrayList<String>();
		for (long i=0; ; i++) {
			myList.add(new String(i+" - "+System.currentTimeMillis()));
			if (i%100000==0) {
				System.out.println("i: "+i+", freeMemory: "+Runtime.getRuntime().freeMemory()/(1024*1024));


Initial URL

Initial Description
This java code, when executed, throws OOM error. 

Java Console:
Exception in thread "main" java.lang.OutOfMemoryError

Heapdump Data:
1STHEAPFREE    Bytes of Heap Space Free: 0 
1STHEAPALLOC   Bytes of Heap Space Allocated: 66666600 

Initial Title
Java OutOfMemory Example

Initial Tags

Initial Language