java - What is the difference between an OutOfMemoryError amd a memory leak -


iam working on java application,whose architecture java-ee component one-end , c++ component on end. when executing app continiously got java.lang.outofmemory error in java heap.when discussed told 1 different java memory leak.if difference between outofmemory error , java memory leak.and how can analyse both things java profilers available in market.could please clarify..

thanks in advance, raghavamoorthy.k

a memory leak in java when objects aren't using cannot garbage collected because still have reference them somewhere.

an outofmemoryerror thrown when there no memory left allocate new objects. caused memory leak, can happen if you're trying hold data in memory @ once.

the jdk includes useful tools jhat , visualvm allow inspect objects in memory , references between them. using these can find objects causing problem.

example

here particularly stupid memory leak. old objects never used, cannot garbage collected. while may seem ridiculous, can create equivalent leak mistake in large projects.

public class leaky {   private static list<object> neverread = new arraylist<object>();   public static void main(string[] args)   {     while(true)     {       neverread.add(new object());     }   } } 

this 1 not memory leak, cause outofmemoryerror somewhere.

public class allocaty {   public static void main(string[] args)   {     long[] array = new long[integer.max_value];     long value = 1l;     for(int ii=integer.max_value; ii>=0; ii--)     {       array[ii] = value++;     }     string str = arrays.tostring(array);     system.out.printf("%d: %s", array.length, str);   } } 

Comments

Popular posts from this blog

python - Scipy curvefit RuntimeError:Optimal parameters not found: Number of calls to function has reached maxfev = 1000 -

c# - How to add a new treeview at the selected node? -

java - netbeans "Please wait - classpath scanning in progress..." -