gbcbr
asked on
Chart heap leaking
Please advise how to stop heap memory leaking in this chart:
public EURUSD_CandleStick_Market() {
datesArrayList = new ArrayList();
pricesArrayList = new ArrayList();
interval = 60000L;
af = new ApplicationFrame("Chart Market");
csr = new CandlestickRenderer();
}
public void aflagc(boolean flag0c) {
mflag0c = flag0c;
}
public void dsControl(boolean ds0) {
mds = ds0;
}
public void eurusd_CandleStick_Market(double[] avg,
java.util.Date[] avg_ts) {
if (avg[0] != 0 && mds == true) {
System.out.println("EUR/USD Market avg[0] = " + avg[0]);
System.out.println("EUR/USD Market avg_ts[0] = " + avg_ts[0]);
System.out.println("EUR/USD Market mds = " + mds);
System.out.println("EUR/USD Market mflag0c = " + mflag0c);
datesArrayList.add(avg_ts[0]);
pricesArrayList.add(new Double(avg[0]));
java.util.Date[] myDates =
new java.util.Date[datesArrayList.size()];
for (int j = 0; j < myDates.length; j++) {
myDates[j] = (java.util.Date)datesArrayList.get(j);
}
double[] myPrices = new double[pricesArrayList.size()];
for (int j = 0; j < myPrices.length; j++) {
myPrices[j] = ((Double)pricesArrayList.get(j)).doubleValue();
}
// System.out.println("Dates: ");
for (int j = 0; j < myDates.length; j++) {
// System.out.println(myDates[j].toString());
}
// System.out.println("Prices: ");
for (int j = 0; j < myPrices.length; j++) {
// System.out.println(myPrices[j]);
}
System.out.println("interval: " + interval);
DefaultHighLowDataset dataset =
OHLCData(myDates, myPrices, myDates[0], interval);
JFreeChart chart = createChart(dataset);
ChartPanel chartPanel = new ChartPanel(chart);
af.setContentPane(chartPanel);
af.setSize(800, 500);
af.setLocation(1600, 800);
if (mflag0c == true) {
af.setVisible(true);
chartPanel.repaint();
} else {
af.setVisible(false);
}
}
}
public DefaultHighLowDataset OHLCData(java.util.Date[] dates,
double[] prices,
java.util.Date startDate,
long interval) {
...........
DefaultHighLowDataset dataset =
new DefaultHighLowDataset("Series 1", finalDates, highs, lows,
opens, closes, volumes);
return dataset;
}
private JFreeChart createChart(final DefaultHighLowDataset dataset) {
final JFreeChart chart =
ChartFactory.createCandlestickChart("Candlestick EUR/USD Market",
"Time", "Price", dataset,
false);
NumberAxis yaxis = (NumberAxis)chart.getXYPlot().getRangeAxis();
yaxis.setAutoRangeIncludesZero(false);
csr.setCandleWidth(10);
chart.getXYPlot().setRenderer(csr);
return chart;
}
}
I have max heap 4096M but in 10 minutes work of this chart its depleted and stack this chart.ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I did it and start app, let's see the result
ASKER
Looks like work!
Good!
ASKER
Thanks again!
ASKER
Please check my question Open position calculation because in 40 minutes market will be close up to Monday and I can't check solution
But I didn't understand how you receive this information and why you just count it when you recieve it
ASKER
ask this questions and I will reply
and then check before JFreeChart chart = createChart(dataset);
if (chart == null)
If it is null we should run this createChart method as we have it now,
if it is not null we should use setDataset method