Solved

Chart heap leaking

Posted on 2011-03-11
9
442 Views
Last Modified: 2012-05-11
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;
    }
}

Open in new window

I have max heap 4096M but in 10 minutes work of this chart its depleted and stack this chart.
0
Comment
Question by:gbcbr
  • 5
  • 4
9 Comments
 
LVL 47

Expert Comment

by:for_yan
ID: 35110951
I think we need tyo make JFreeChart chart and instance variable
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
 
0
 
LVL 47

Accepted Solution

by:
for_yan earned 500 total points
ID: 35111001
To do that you declare

JFreeChart chart;
ChartPanel chartPanel;


just after class declaration

and then wehere we have now

  JFreeChart chart = createChart(dataset);

instead of this line we put:

if(chart == null) {
chart = createChart(dataset);
  chartPanel = new ChartPanel(chart);

            af.setContentPane(chartPanel);
} else {
chart.getXYPlot().setDataset(dataset);
chartPanel.repaint();

}

Something along this line should work



0
 

Author Comment

by:gbcbr
ID: 35111038
I did it and start app, let's see the result
0
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 

Author Comment

by:gbcbr
ID: 35111266
Looks like work!
0
 
LVL 47

Expert Comment

by:for_yan
ID: 35111464
Good!
0
 

Author Comment

by:gbcbr
ID: 35111472
Thanks again!
0
 

Author Comment

by:gbcbr
ID: 35112251
Please check my question Open position calculation because in 40 minutes market will be close up to Monday and I can't check solution
0
 
LVL 47

Expert Comment

by:for_yan
ID: 35112327
But I didn't understand how you receive this information and why you just count it when you recieve it
0
 

Author Comment

by:gbcbr
ID: 35112336
ask this questions and I will reply
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
egit plugin on eclipse 8 63
web services creation SOAP vs REST 5 40
Convert from a json string array to a Java object 3 31
going to wrong jsp page 2 20
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question