Saving Charts Eating Up My Memory

4 posts, 0 answers
  1. AI_IT
    AI_IT avatar
    2 posts
    Member since:
    Nov 2007

    Posted 27 Jun 2009 Link to this post

    Hi,
    I am using Telerik RadChart for our sales persons target&realization&performance graphics (at least 2000 person's charts * 3 times for every entrance to the system). When i use asp.net for creating images on the fly, there is going to have a memory problem in IIS. It is going higher and higher and at last application server gives "Out of memory" error. So i determined that, i am going to preprocess those images and will going to show.  So there will not be any problem on web server i thought.

    But, i have another problem on this new issue. I take all the code to the winform and create a new windows application to create all charts. After that, when i tried to create charts, again the memory usage is going higher for each time i saved the chart.

    In my Code, there is a radChart1 object, which has one serie for a line, XAxis and YAxis properties are also specified. So in the code behind, I wrote this code;

    ******************************
    DataSet

    dsMsas = new DataSet(); //

    dsMsas = df.GetMsas(); // it is getting from a database function class (all sales persons)

     

    for (int i = 0; i < dsMsas.Tables[0].Rows.Count; i++)

    {

    Telerik.WinControls.UI.

     

    RadChart rc = new Telerik.WinControls.UI.RadChart();

    rc = (Telerik.WinControls.UI.

     

    RadChart) radChart1.Clone();

    try

    {

     

     

    string intMsaCode = dsMsas.Tables[0].Rows[i][0].ToString();
    DataSet ds = new DataSet();

    ds = df.GetMI(intMsaCode); //get Market Index data for sales persons

     

    Double dblMinValue = 0, dblMaxValue = 0;

    ChartSeries miDataSeries = rc.GetSeries("Series 1"); // only one serie in the chart

    rc.ChartTitle.TextBlock.Text =

     

    "MI " + ds.Tables[0].Rows[0][2].ToString() + " / " + ds.Tables[0].Rows[0][3].ToString();

    if (miDataSeries != null)

    {

    dblMinValue =

    Convert.ToDouble(ds.Tables[0].Rows[0][1]);

     

     

    dblMaxValue = dblMinValue;

    miDataSeries.DefaultLabelValue =

    "#Y{N0}";

    foreach (DataRow dbRow in ds.Tables[0].Rows)

    {

     

    if (dblMinValue > Convert.ToDouble(dbRow["pdMIMS"]))

    dblMinValue =

    Convert.ToDouble(dbRow["pdMIMS"]);

    if (dblMaxValue < Convert.ToDouble(dbRow["pdMIMS"]))

    dblMaxValue =

    Convert.ToDouble(dbRow["pdMIMS"]);

     

     

    rc.PlotArea.XAxis.AddItem(dbRow[

    "psMonthName"].ToString().Substring(0, 3));

     

     

    miDataSeries.AddItem(

    Convert.ToDouble(dbRow["pdMIMS"]));

     

     

    }

    }

     

    double dblAvgValue = Convert.ToInt32((dblMaxValue - dblMinValue) / ds.Tables[0].Rows.Count);

    rc.PlotArea.YAxis.MaxValue =

    Convert.ToDouble(Convert.ToInt32(dblMaxValue) + dblAvgValue);

     

     

    rc.PlotArea.YAxis.MinValue = 

    Convert.ToDouble(Convert.ToInt32(dblMinValue) - dblAvgValue);

    int intStep = Convert.ToInt32((rc.PlotArea.YAxis.MaxValue - rc.PlotArea.YAxis.MinValue) / ds.Tables[0].Rows.Count);

    rc.PlotArea.YAxis.Step = intStep <= 0 ? 1 : intStep;

     

    rc.Save(

    "MainPageImages/MI/" + intMsaCode + "_MI.png", System.Drawing.Imaging.ImageFormat.Png);
    //after this part the memory is going higher, when i throw this part there is nothing happened, no memory usage.

    miDataSeries.Clear();

    rc.PlotArea.YAxis.Clear();

    rc.PlotArea.XAxis.Clear();

    rc.Dispose();

    rc = 

    null;

     

     

    }

     

    catch (Exception ex)

    {

     

    //nothing

     

    string strE = ex.Message;

    }

    }

    dsMsas =

    null;

    ***************************************** 
    SO, what can i do for that, i must solve this problem urgently.

  2. Dwight
    Admin
    Dwight avatar
    475 posts

    Posted 02 Jul 2009 Link to this post

    Hi Selin,

    First, let me appologize for the delayed answer. We will investigate the cause of the problem and provide a fix in some of the comming releases.

    What I noted in your code is that you Clone radChart1 many times. What I can suggest is try clone the chart one time only and re-use the cloned chart. That should significantly decrease the memory preassure you experience.

    Let me know if that is at least a partial solution to the problem.

    Best regards,
    Evtim
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  3. UI for WinForms is Visual Studio 2017 Ready
  4. AI_IT
    AI_IT avatar
    2 posts
    Member since:
    Nov 2007

    Posted 02 Jul 2009 Link to this post

    Hi again,
    Firstfully, Thanks for your reply...
    After i send this code to you, i changed the code many times to use memory more efficiently. But whenever i save the chart, the memory usage is going higher. On the other hand, saving chart is creating nearly 14KB images for each loop, and when i close saving chart code part, memory does not change highly. I tried with save chart code and saw that after 100 images created then memory goes to 400 MB, but when i close save chart code then memory is not going higher than 80 MB. But I must save chart for over 1800 images.

    I am sending the last code part for that tryings.

    *******************

                DataSet dsMsas = df.GetMsas();
                Double dblMinValue = 0, dblMaxValue = 0, dblAvgValue=0;
                ChartSeries miDataSeries = radChart1.GetSeries("Series 1");
                string intMsaCode="";

                for (int i = 0; i < dsMsas.Tables[0].Rows.Count; i++)
                {
                    dblMinValue = 0; dblMaxValue = 0; dblAvgValue = 0;
                    try
                    {
                        intMsaCode = dsMsas.Tables[0].Rows[i][0].ToString();//int.Parse(Request.QueryString["MsaCode"].ToString());
                        DataSet ds = df.GetMI(intMsaCode);
                        radChart1.ChartTitle.TextBlock.Text = "MI Gelişim " + ds.Tables[0].Rows[0][2].ToString() + " / " + ds.Tables[0].Rows[0][3].ToString();

                        if (miDataSeries != null)
                        {
                            dblMinValue = Convert.ToDouble(ds.Tables[0].Rows[0][1]);
                            dblMaxValue = dblMinValue;
                            miDataSeries.DefaultLabelValue = "#Y{N0}";

                            foreach (DataRow dbRow in ds.Tables[0].Rows)
                            {
                                if (dblMinValue > Convert.ToDouble(dbRow["pdMIMS"]))
                                    dblMinValue = Convert.ToDouble(dbRow["pdMIMS"]);
                                if (dblMaxValue < Convert.ToDouble(dbRow["pdMIMS"]))
                                    dblMaxValue = Convert.ToDouble(dbRow["pdMIMS"]);
                                radChart1.PlotArea.XAxis.AddItem(dbRow["psMonthName"].ToString().Substring(0, 3));
                                miDataSeries.AddItem(Convert.ToDouble(dbRow["pdMIMS"]));
                            }
                        }

                        dblAvgValue = Convert.ToInt32((dblMaxValue - dblMinValue) / ds.Tables[0].Rows.Count);
                        radChart1.PlotArea.YAxis.MaxValue = Convert.ToDouble(Convert.ToInt32(dblMaxValue) + dblAvgValue);
                        radChart1.PlotArea.YAxis.MinValue = Convert.ToDouble(Convert.ToInt32(dblMinValue) - dblAvgValue);
                        int intStep = Convert.ToInt32((radChart1.PlotArea.YAxis.MaxValue - radChart1.PlotArea.YAxis.MinValue) / ds.Tables[0].Rows.Count);
                        radChart1.PlotArea.YAxis.Step = intStep <= 0 ? 1 : intStep;
                        radChart1.Save("MainPageImages/MI/" + intMsaCode + "_MI.png", System.Drawing.Imaging.ImageFormat.Png); // when i close this part memory is not going higher.
                        miDataSeries.Clear();
                        radChart1.PlotArea.YAxis.Clear();
                        radChart1.PlotArea.XAxis.Clear();
                        ds.Clear();
                        ds.Dispose();
                        ds = null;
                    }
                    catch (Exception ex)
                    {//nothing
                        string strE = ex.Message;
                    }
                }
                dsMsas = null;

    **************************************
    I hope, it (the problem) is in my code, if not i must change all those graphics with the reporting chart object which is not my willing to do for shortly term solution.

    Another question is for asp.net charting and again memory usage. Do you have any trouble or problem on asp.net application, again i use chart object and the charts are being created on the fly. So there is again memory usage failure when over then 1500 user come in one hour period.

    Thanks again,
  5. Dwight
    Admin
    Dwight avatar
    475 posts

    Posted 07 Jul 2009 Link to this post

    Hi Selin,

    What I can further suggest is to Dispose of the RadChart after each Save operation. Something like:
    for (int i = 0; i < dsMsas.Tables[0].Rows.Count; i++) 
        using (RadChart radChart1 = new RadChart()) 
        { 
          ... 
        } 
    or by calling radChart1.Dispose() to ensure disposal of native resources used by the chart.

    Other than that, we will investigate what is the cause for the memory leaks.

    On the ASP.NET charting problems - we are currently unaware of having memory leaks. The page life cycle should aid the disposal of the used charts. Further details on the usage of the ASP.NET chart would greatly help us find the cause of the problems and provide a solution. (please, open a support ticket for the ASP.NET RadChart).

    Kind regards,
    Evtim
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
Back to Top