Link to home
Start Free TrialLog in
Avatar of Jasbir21
Jasbir21

asked on

Urgent - java.lang.OutofMemoryError:Java heap space


Hi ,

Pls help,

When i run the codes i get errror:

exception in thread "AWT- EventQueue -1" java.lang.OutofMemoryError:Java heap space.

What do i do ?
SOLUTION
Avatar of StillUnAware
StillUnAware
Flag of Lithuania image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of CEHJ
You may be creating infinite recursion, such as when a method is called in a listener that causes that listener to receive events
Avatar of Jasbir21
Jasbir21

ASKER

hi,

actually i am using applets...when i try appletviewer -Xmx256M example.html

had error : unsupported option : - Xmx256M
Do this:

appletviewer -J-Xmx256M
You can't pass options to appletviewer like that. It's unlikely to help anyway if there are errors
i am using a for loop where the number of iterations can go up to 500000.

-->>>
appletviewer -J-Xmx256M example.html

if there a way to embede this command in the code or html file. because if the user is not using appletviewer , use browser (internet explorer)?

thanks
>> am using a for loop where the number of iterations can go up to 500000.


That's of little consequence. What you're *doing* in it likely *is*
>>if there a way to embede this command in the code or html file.

AFAIK no. Did it 'solve' the problem anyway?
i am drawing a scatter graph ..


                  for (int i = 0; i < iterations; i++)
                  {  
                        series = new XYSeries("S" + i);
                        for (int j = 0; j < years+1; j++)
                        {  
                              series.add(j, score[j][i]);
                                                      }
                        dataset.addSeries(series);
                  }
actually, with appletviewer (appletviewer -J-Xmx256M example.html )

, it solve, but when i put on server..

i cannot use appletviewer .. i need to use internet explorer...

thanks

Hmm. That's a third party library i take it, so that makes things trickier
yup..jfreegraph
You'll need to either hand-optimise the code or use a different library probably
what do you mean by  ->>You'll need to either hand-optimise the code

thanks
Look at their source to see if you can optimise it
but is there a way to allocate jvm memory dynamically in the code?
The code runs well up to iteration of 7000 .

Once it was able to be runned up to 20 000 . But when i tried again, got the memory error..thanks

>> but is there a way to allocate jvm memory dynamically in the code?

No, not practicably

Their code may be buggy. Try another library. JFreeChar?
JFreeChar=JFreeChart
actually, i need to use jfreechart .  
one of the requirements from the lecturer

for (int i = 0; i < iterations; i++)
               {  
                    series = new XYSeries("S" + i);
                    for (int j = 0; j < years+1; j++)
                    {  
                         series.add(j, score[j][i]);
                                             }
                    dataset.addSeries(series);
               }

- is there a way to disallocate memory after this loop..so that when it run again,
memory can be reused .thanks
>>- is there a way to disallocate memory after this loop..so that when it run again,

No, that is done by the garbage collector and it's only advisory to call gc. You may try it though

System.gc();
Thread.sleep(50);
You can try with WeakReference
i still get the out of memory error ...

--->>
You can try with WeakReference  ... what do you mean by that ? thanks
>> actually, i need to use jfreechart .  

If this is the case, why a you still concerning yourself with another one?
oh..ic..Weak Reference is a third party library as well ?

i thought , maybe putting a reference or somehing in side..
A WeakReference could only conceivably be of use to you if you *were* using it in *their* code
For a specific machine (on Windows) You can set the memory amount to 256MB to be used in browser this way:

in Control Panel find Java applet, there in "Java" -> "Java Applet Runtime Settings" -> "View..." -> "JRE Settings" set the "Java Runtime Parameters" field to "-Xmx256M" or "-J-Xmx256M". You'll have to find out which one of two is correct.
for (int i = 0; i < iterations; i++)
               {  
                    WeakReference reference = new WeakReference(new XYSeries("S" + i));
                    XYSeries series = (XYSeries)reference.get();
                    for (int j = 0; j < years+1; j++)
                    {  
                         series.add(j, score[j][i]);
                                             }
                    dataset.addSeries(series);
               }
I am not sure that it ll help u or not, but u can give it a shot.
Why you need to loop say 50 000 times , all together? Why can't you divide the iteration?? Say putting part by part to the garph.
Changing the JRE settings to gain a solution is game.
--->

-> "Java Applet Runtime Settings" -> "View..." -> "JRE Settings" set the "Java Runtime Parameters" field to "-Xmx256M" or "-J-Xmx256M".

I am still gettingout of memory error ...

--->
 WeakReference reference = new WeakReference(new XYSeries("S" + i));
it does not recognise the weakreference symbol...

thanks
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Are you sure that there is not an infinite loop in your code?
hi,

i dont think there is  any infinite loop . it works with 5000...

how do i put it in on the graph part by part...

  if(i<5000)

series = new XYSeries("Iteration" + i);

          else      
       ser=new XYSeries("DS" + i);

is it something like this? thanks
>i dont think there is  any infinite loop . it works with 5000...

So you really use much memory. You need to use less memory. For example you must check if you create variable not really needed or duplicated.
actually, the codes work up to 10000 when i try with line graph...
it only happens when i try with scatter graph
Are you using the data points for any other purpose than displaying them?
just for displaying them..thanks
What API are you now using - i'm rather confused now
swingx and awt..

and jfreegraph
jfreegraph has the  methods/classes to display them ..

............

series.add(j, score[j][i]);
                                             }
                    dataset.addSeries(series);
----------------- like this is to add
What's the fully-qualified name of the main chart class you're using?
XYPlot plot = (XYPlot) chart.getPlot();
XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer();
NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis();
                domainAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());


import org.jfree.chart.axis.NumberAxis;

import org.jfree.chart.plot.XYPlot;
import org.jfree.data.xy.XYSeries;
import org.jfree.data.xy.XYSeriesCollection;
import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
I don't know this API but it may be a good idea for you to post the code that is causing the problem anyway
for (int i = 0; i < iterations; i++)
               {  
                    series = new XYSeries("S" + i);
                    for (int j = 0; j < years+1; j++)
                    {  
                         series.add(j, score[j][i]);
                                             }
                    dataset.addSeries(series);
               }
this is the code to add scores...

and the codes below is to display them..

//create a chart to display the competency range
                chart = ChartFactory.createScatterPlot(
                  "Example",    
                  "X ",            
                  "Y",    
                  dataset,                  // data
                  PlotOrientation.VERTICAL,
                  false,                    
                  true,                    
                  false                    
                  );
        
                  XYPlot plot = (XYPlot) chart.getPlot();

                  XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer();
                  renderer.setShapesVisible(true);
                  renderer.setBaseShapesFilled(false);
            
                  plot.setRenderer(renderer);
            
            
                  chartPanel=new ChartPanel(chart);
>               XYPlot plot = (XYPlot) chart.getPlot();
>
>               XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer();
>               renderer.setShapesVisible(true);
>               renderer.setBaseShapesFilled(false);
>         
>               plot.setRenderer(renderer);

cycle risk.


>for (int i = 0; i < iterations; i++)
>...
>for (int j = 0; j < years+1; j++)
>...

too many object.
How is 'iterations' set?
the user can enter the number of iterations....
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ok..got the error..what should i do now ?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
thanks a lot :-)
:-)
glad to help
Glad to hear that u r through :-)