OutOfMemory error

M

mani

Hi all
can anyone say at which situation OutOfMemory error will
come ? Any simple code to reproduce OutOfMemory error ?

mani
 
T

Thomas Kellerer

mani said:
Hi all
can anyone say at which situation OutOfMemory error will
come ? Any simple code to reproduce OutOfMemory error ?

mani

public static void main(String args[])
{
ArrayList l = new ArrayList();
while (true)
{
String s = new String("This will fill up memory");
l.add(s);
}
}
 
M

Michael Borgwardt

mani said:
Hi all
can anyone say at which situation OutOfMemory error will
come ?

An OutOfMemoryError will occur when the JVM tries to allocate memory (usually for a new
object) but there is not enough free memory in the heap *and* the heap cannot grow
because it has already reached its limit (set during the invocation of "java") *and*
garbage collection has not been able to free enough memory.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,777
Messages
2,569,604
Members
45,228
Latest member
MikeMichal

Latest Threads

Top