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
What do i do ?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
You may be creating infinite recursion, such as when a method is called in a listener that causes that listener to receive events
ASKER
hi,
actually i am using applets...when i try appletviewer -Xmx256M example.html
had error : unsupported option : - Xmx256M
actually i am using applets...when i try appletviewer -Xmx256M example.html
had error : unsupported option : - Xmx256M
Do this:
appletviewer -J-Xmx256M
appletviewer -J-Xmx256M
You can't pass options to appletviewer like that. It's unlikely to help anyway if there are errors
ASKER
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
-->>>
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*
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?
AFAIK no. Did it 'solve' the problem anyway?
ASKER
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);
}
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);
}
ASKER
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
, 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
ASKER
yup..jfreegraph
You'll need to either hand-optimise the code or use a different library probably
ASKER
what do you mean by ->>You'll need to either hand-optimise the code
thanks
thanks
Look at their source to see if you can optimise it
ASKER
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
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?
No, not practicably
Their code may be buggy. Try another library. JFreeChar?
JFreeChar=JFreeChart
ASKER
actually, i need to use jfreechart .
ASKER
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
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);
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
ASKER
i still get the out of memory error ...
--->>
You can try with WeakReference ... what do you mean by that ? thanks
--->>
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?
If this is the case, why a you still concerning yourself with another one?
ASKER
oh..ic..Weak Reference is a third party library as well ?
i thought , maybe putting a reference or somehing in side..
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.
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.
{
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.
Changing the JRE settings to gain a solution is game.
ASKER
--->
-> "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
-> "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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Are you sure that there is not an infinite loop in your code?
ASKER
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...
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.
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.
ASKER
actually, the codes work up to 10000 when i try with line graph...
it only happens when i try with scatter graph
it only happens when i try with scatter graph
Are you using the data points for any other purpose than displaying them?
ASKER
just for displaying them..thanks
What API are you now using - i'm rather confused now
ASKER
swingx and awt..
and jfreegraph
and jfreegraph
ASKER
jfreegraph has the methods/classes to display them ..
............
series.add(j, score[j][i]);
}
dataset.addSeries(series);
----------------- like this is to add
............
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?
ASKER
XYPlot plot = (XYPlot) chart.getPlot();
XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer();
NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis();
domainAxis.setStandardTick Units(Numb erAxis.cre ateInteger TickUnits( ));
import org.jfree.chart.axis.Numbe rAxis;
import org.jfree.chart.plot.XYPlo t;
import org.jfree.data.xy.XYSeries ;
import org.jfree.data.xy.XYSeries Collection ;
import org.jfree.chart.renderer.x y.XYLineAn dShapeRend erer;
XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer();
NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis();
domainAxis.setStandardTick
import org.jfree.chart.axis.Numbe
import org.jfree.chart.plot.XYPlo
import org.jfree.data.xy.XYSeries
import org.jfree.data.xy.XYSeries
import org.jfree.chart.renderer.x
ASKER
import org.jfree.chart.ChartPanel ;
import org.jfree.chart.JFreeChart ;
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
ASKER
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.createScatter Plot(
"Example",
"X ",
"Y",
dataset, // data
PlotOrientation.VERTICAL,
false,
true,
false
);
XYPlot plot = (XYPlot) chart.getPlot();
XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer();
renderer.setShapesVisible( true);
renderer.setBaseShapesFill ed(false);
plot.setRenderer(renderer) ;
chartPanel=new ChartPanel(chart);
{
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.createScatter
"Example",
"X ",
"Y",
dataset, // data
PlotOrientation.VERTICAL,
false,
true,
false
);
XYPlot plot = (XYPlot) chart.getPlot();
XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer();
renderer.setShapesVisible(
renderer.setBaseShapesFill
plot.setRenderer(renderer)
chartPanel=new ChartPanel(chart);
> XYPlot plot = (XYPlot) chart.getPlot();
>
> XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer();
> renderer.setShapesVisible( true);
> renderer.setBaseShapesFill ed(false);
>
> plot.setRenderer(renderer) ;
cycle risk.
>for (int i = 0; i < iterations; i++)
>...
>for (int j = 0; j < years+1; j++)
>...
too many object.
>
> XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer();
> renderer.setShapesVisible(
> renderer.setBaseShapesFill
>
> 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?
ASKER
the user can enter the number of iterations....
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
ok..got the error..what should i do now ?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thanks a lot :-)
:-)
glad to help
Glad to hear that u r through :-)