Computing Magazine

Out Of Memory Error In Java

Posted on the 09 May 2014 by Abhishek Somani @somaniabhi
A Simple Example of creating Out Of Memory Error in a Java Program . It is an Error , so you can catch it also .

import java.util.*;
public class OutOfMemoryTest
{
public static void main(String[] args)
{
try
{
LinkedList list = new LinkedList();
while(true)
{
list.add(new Object());
}
}
catch(Throwable e)
{
System.out.println("caught it ");
}


}
}
Out Of Memory Error In Java

Back to Featured Articles on Logo Paperblog

Magazines