Page 1 of 1

Memory Leak in TeeChart Pocket OnPaint !

Posted: Thu Mar 16, 2006 8:30 am
by 9640546
Hi,

I have detected a memory leak in the OnPaint method on the TeeChart Pocket Version. When i disable the painting with overwriting the OnPaint method, the memory does not grow up. I always have constant number of points (before addind a new point, i remove the oldest point.)

Code: Select all

// Form1.cs---------------------------------
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Steema.TeeChart.Pocket;
using Steema.TeeChart.Tools;


namespace TeeChartV2Test
{
    public partial class frmMain : Form
    {
        private Steema.TeeChart.Styles.FastLine m_teechartLine1 = null;
        private Steema.TeeChart.Styles.FastLine m_teechartLine2 = null;
        private Steema.TeeChart.Styles.FastLine m_teechartLine3 = null;
        private Steema.TeeChart.Styles.FastLine m_teechartLine4 = null;
        private Steema.TeeChart.Styles.FastLine m_teechartLine5 = null;
        private DateTime                        m_dtCurrentTime = DateTime.Now;
        private Random                          m_rnd           = new Random();

        public frmMain ()
        {
            InitializeComponent();
            InitializeTeeChart();
            FillTeeChart();
            tmrAddValues.Interval = 2000;
            tmrAddValues.Enabled = true;
        }

        /// -------------------------------------------------------------------
        /// <summary>
        /// Method name		:	InitializeTeeChart
        /// Author			:	TJo
        ///	Date			:	11.10.2005
        /// </summary>
        /// -------------------------------------------------------------------
        private void InitializeTeeChart()
        {
            m_MyTeeChart.Legend.Visible = true;
            m_MyTeeChart.Aspect.View3D  = false;
            m_MyTeeChart.AutoRepaint    = false;

            // move legend
            m_MyTeeChart.Legend.LegendStyle = Steema.TeeChart.LegendStyles.Series;
            m_MyTeeChart.Legend.Alignment   = Steema.TeeChart.LegendAlignments.Bottom;
            m_MyTeeChart.Legend.Left        = 0;

            // create axies
            m_MyTeeChart.Axes.Left.Automatic    = false;
            m_MyTeeChart.Axes.Left.Minimum      = 0;
            m_MyTeeChart.Axes.Left.Maximum      = 100;
            m_MyTeeChart.Axes.Left.Grid.Visible = true;

            m_MyTeeChart.Axes.Right.Grid.Visible = false;
            m_MyTeeChart.Axes.Right.Automatic    = false;
            m_MyTeeChart.Axes.Right.Minimum      = 0;
            m_MyTeeChart.Axes.Right.Maximum      = 100;
            m_MyTeeChart.Axes.Right.Visible      = true;

            
            m_MyTeeChart.Axes.Bottom.Grid.Visible = true;
            m_MyTeeChart.Axes.Bottom.Automatic    = false;

            Steema.TeeChart.Axis axisCustom = new Steema.TeeChart.Axis( m_MyTeeChart.Chart );
            axisCustom.Grid.Visible         = false;
            axisCustom.OtherSide            = true;
            axisCustom.RelativePosition     = -7;
            axisCustom.Automatic            = false;
            axisCustom.Minimum              = 0;
            axisCustom.Maximum              = 100;
            axisCustom.Visible              = true;
            m_MyTeeChart.Axes.Custom.Add( axisCustom );

            // resize chart cause of CustomAxis 
            m_MyTeeChart.Panel.MarginRight = 8;

            // add lines
            m_teechartLine1                 = new Steema.TeeChart.Styles.FastLine( m_MyTeeChart.Chart );
            m_teechartLine1.Visible         = true;
            m_teechartLine1.VertAxis        = Steema.TeeChart.Styles.VerticalAxis.Left;
            m_teechartLine1.LinePen.Width   = 3;
            m_teechartLine1.Color           = Color.Red;

            m_teechartLine2                 = new Steema.TeeChart.Styles.FastLine( m_MyTeeChart.Chart );
            m_teechartLine2.Visible         = true;
            m_teechartLine2.VertAxis        = Steema.TeeChart.Styles.VerticalAxis.Right;
            m_teechartLine2.LinePen.Width   = 3;
            m_teechartLine2.Color           = Color.Blue;

            m_teechartLine3                 = new Steema.TeeChart.Styles.FastLine( m_MyTeeChart.Chart );
            m_teechartLine3.Visible         = true;
            m_teechartLine3.VertAxis        = Steema.TeeChart.Styles.VerticalAxis.Custom;
            m_teechartLine3.CustomVertAxis  = m_MyTeeChart.Axes.Custom[0];
            m_teechartLine3.LinePen.Width   = 3;
            m_teechartLine3.Color           = Color.Green;

            m_teechartLine4                 = new Steema.TeeChart.Styles.FastLine( m_MyTeeChart.Chart );
            m_teechartLine4.Visible         = true;
            m_teechartLine4.VertAxis        = Steema.TeeChart.Styles.VerticalAxis.Right;
            m_teechartLine4.LinePen.Width   = 3;
            m_teechartLine4.Color           = Color.Yellow;

            m_teechartLine5                 = new Steema.TeeChart.Styles.FastLine( m_MyTeeChart.Chart );
            m_teechartLine5.Visible         = true;
            m_teechartLine5.VertAxis        = Steema.TeeChart.Styles.VerticalAxis.Custom;
            m_teechartLine5.CustomVertAxis  = m_MyTeeChart.Axes.Custom[0];
            m_teechartLine5.LinePen.Width   = 3;
            m_teechartLine5.Color           = Color.White;

            // set date/time format 
            m_teechartLine1.XValues.DateTime               = true;
            m_MyTeeChart.Axes.Bottom.Labels.DateTimeFormat = "dd.MM.yyyy HH:mm";
            m_MyTeeChart.Axes.Bottom.Labels.MultiLine      = true;
        }

        /// -------------------------------------------------------------------
        /// <summary>
        /// Method name		:	NormCurrentTime 
        /// Author			:	TJo
        ///	Date			:	08.03.2006
        /// </summary>
        /// -------------------------------------------------------------------
        static private DateTime NormTime (DateTime dtTime)
        {
            dtTime = dtTime.AddMilliseconds( -dtTime.Millisecond );
            dtTime = dtTime.AddSeconds( -dtTime.Second );
            return dtTime;
        }

        /// -------------------------------------------------------------------
        /// <summary>
        /// Method name		:	FillChart 
        /// Author			:	TJo
        ///	Date			:	08.03.2006
        /// </summary>
        /// -------------------------------------------------------------------
        private void FillTeeChart ()
        {
            // get start time
            m_dtCurrentTime = NormTime( DateTime.Now );
            m_dtCurrentTime = m_dtCurrentTime.AddDays(-4);

            // fill points
            while(m_dtCurrentTime < NormTime( DateTime.Now ))
            {
                // add points
                m_teechartLine1.Add( m_dtCurrentTime, m_rnd.Next( 0, 100 ) );
                m_teechartLine2.Add( m_dtCurrentTime, m_rnd.Next( 0, 100 ) );
                m_teechartLine3.Add( m_dtCurrentTime, m_rnd.Next( 0, 100 ) );
                m_teechartLine4.Add( m_dtCurrentTime, m_rnd.Next( 0, 100 ) );
                m_teechartLine5.Add( m_dtCurrentTime, m_rnd.Next( 0, 100 ) );

                // next time
                m_dtCurrentTime = m_dtCurrentTime.AddMinutes( 1 );
            }
        }


        /// -------------------------------------------------------------------
        /// <summary>
        /// Method name		:	RecalcXAxies 
        /// Author			:	TJo
        ///	Date			:	08.03.2006
        /// </summary>
        /// -------------------------------------------------------------------
        public void RecalcXAxies ( )
        {
            // get time to display
            DateTime dtBegin = m_dtCurrentTime.AddHours(-4);

            // set min
            m_MyTeeChart.Axes.Bottom.Minimum = dtBegin.ToOADate();

            // set max
            m_MyTeeChart.Axes.Bottom.Maximum = m_dtCurrentTime.ToOADate();
        }

        /// -------------------------------------------------------------------
        /// <summary>
        /// Method name		:	RecalcXAxies 
        /// Author			:	TJo
        ///	Date			:	08.03.2006
        /// </summary>
        /// -------------------------------------------------------------------
        public void AddNewPoint ( Steema.TeeChart.Styles.FastLine teechartLine, DateTime dtTimeValue)
        {
            // remove first point
            teechartLine.XValues.RemoveAt( 0 );
            teechartLine.YValues.RemoveAt( 0 );

            // add new point
            teechartLine.Add( dtTimeValue, m_rnd.Next( 0, 100 ) );
            teechartLine.Title = "Number of Points = " + teechartLine.XValues.Count;
        }


        /// -------------------------------------------------------------------
        /// <summary>
        /// Method name		:	timer1_Tick 
        /// Author			:	TJo
        ///	Date			:	08.03.2006
        /// </summary>
        /// -------------------------------------------------------------------
        private void timer1_Tick ( object sender, EventArgs e )
        {
            // disable timer
            tmrAddValues.Enabled = false;

            // stop redraw
            m_MyTeeChart.AutoRepaint = false;

            // set new timevalue
            m_dtCurrentTime =  m_dtCurrentTime.AddMinutes( 1 );

            // add new points
            AddNewPoint( m_teechartLine1, m_dtCurrentTime );
            AddNewPoint( m_teechartLine2, m_dtCurrentTime );
            AddNewPoint( m_teechartLine3, m_dtCurrentTime );
            AddNewPoint( m_teechartLine4, m_dtCurrentTime );
            AddNewPoint( m_teechartLine5, m_dtCurrentTime );
            
            // recalc axies units
            RecalcXAxies();

            // redraw chart
            m_MyTeeChart.AutoRepaint = true;
            m_MyTeeChart.Refresh();

            // start timer
            tmrAddValues.Enabled = true;
        }
    }
}

Code: Select all

// Form1.Designer.cs---------------------------------
namespace TeeChartV2Test
{
    partial class frmMain
    {
        /// <summary>
        /// Erforderliche Designervariable.
        /// </summary>
        private System.ComponentModel.IContainer components = null;

        /// <summary>
        /// Verwendete Ressourcen bereinigen.
        /// </summary>
        /// <param name="disposing">True, wenn verwaltete Ressourcen gelöscht werden sollen; andernfalls False.</param>
        protected override void Dispose ( bool disposing )
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose( disposing );
        }

        #region Vom Windows Form-Designer generierter Code

        /// <summary>
        /// Erforderliche Methode für die Designerunterstützung.
        /// Der Inhalt der Methode darf nicht mit dem Code-Editor geändert werden.
        /// </summary>
        private void InitializeComponent ()
        {
            this.m_MyTeeChart = new MyTeeChart();
            this.tmrAddValues = new System.Windows.Forms.Timer();
            this.SuspendLayout();
            // 
            // m_MyTeeChart
            // 
            this.m_MyTeeChart.AutoRepaint = true;
            this.m_MyTeeChart.Dock = System.Windows.Forms.DockStyle.Fill;
            this.m_MyTeeChart.Location = new System.Drawing.Point( 0, 0 );
            this.m_MyTeeChart.Name = "m_MyTeeChart";
            this.m_MyTeeChart.Size = new System.Drawing.Size( 819, 389 );
            this.m_MyTeeChart.TabIndex = 0;
            this.m_MyTeeChart.Text = "TeeChart V2";
            // 
            // tmrAddValues
            // 
            this.tmrAddValues.Interval = 5000;
            this.tmrAddValues.Tick += new System.EventHandler( this.timer1_Tick );
            // 
            // frmMain
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF( 96F, 96F );
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Dpi;
            this.AutoScroll = true;
            this.ClientSize = new System.Drawing.Size( 819, 389 );
            this.Controls.Add( this.m_MyTeeChart );
            this.Location = new System.Drawing.Point( 50, 50 );
            this.Name = "frmMain";
            this.Text = "TeeChart V2 Test...";
            this.ResumeLayout( false );

        }

        #endregion

        private System.Windows.Forms.Timer tmrAddValues;
        private MyTeeChart m_MyTeeChart;
    }
}

Code: Select all

// MyTeeChart.cs---------------------------------
using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using System.Windows.Forms;
using Steema.TeeChart.Pocket;
using Steema.TeeChart.Tools;


namespace TeeChartV2Test
{
        public class MyTeeChart : Steema.TeeChart.Pocket.TChart
    {

        /// <summary>
        /// 
        /// </summary>
        /// <param name="e"></param>
		protected override void OnPaintBackground(PaintEventArgs e)
		{
		}

        /// <summary>
        /// OnPaint
        /// </summary>
        /// <param name="e"></param>
		protected override void OnPaint(PaintEventArgs e)
        {
            // return;

            // call base class
            base.OnPaint( e );
        }

    }
}


[/code]

Posted: Mon Mar 20, 2006 3:01 pm
by narcis
Hi VESCON,

Thanks for the report. I've created an example using the code you posted but I'm unable to see which is the problem you report. Could you please give us the exact instructions we need to follow to observe that or extend on that information?

Thanks in advance.

Posted: Thu Mar 23, 2006 8:32 am
by 9640546
Hi,

yes, i hope ;)

Here the Problem:
We use a beckoff embedded PC CX1000-XXXX (http://www.beckhoff.de/) on witch runs WindowsCE 5.0.
Our application monitors water levels of differnt watergates. This application runs 24 hours a day and 7 days a week.
This application is developed with VS2005(C#). We have two view modes. One is the textview, on witch we only show the
current levels as text. The second view is the teechart with some fastlines.
When i activate the textview, no memory grows up, even though points where added (and removed) to the teechart.
When i switch to the chart, after some hours, the memory is increased by e.g. 3 MB.
After that notice, i developed a small test-application (see above).
I have tried this application in an emulator now, but there the effect does not take place.
It seems, that you must use a device with WindowsCE 5.0.

ciao Thomas

PS: In the Version 1.0 this problem doesn't occur !

Posted: Thu Mar 23, 2006 10:16 am
by narcis
Hi Thomas,

Thanks for the information.

Latelly we did some changes in TeeChart.Pocket.dll to solve an issue a customer reported which involved the chart being constantly repainted. This fix will be made public soon in the next debug build. I'd suggest you to wait for that release, which will be announced here, and if the problem persists contact us again and we will try to investigate further.

Posted: Wed May 10, 2006 7:08 am
by 9640546
Hi,

I have now installed the new Version of TeeChart(V2.0.2306.2631) and the bug is still present!

BTW: What about the LineWidth Property ? Is it implemented on the Pocket-Version ? We want to show the importent lines in another linewidth, but it doesn't work!

ciao Thomas

Posted: Wed May 10, 2006 11:37 am
by narcis
Hi Thomas,
I have now installed the new Version of TeeChart(V2.0.2306.2631) and the bug is still present!
Have you tested the example project you posted in a non-Beckhoff Windows CE device?
BTW: What about the LineWidth Property ? Is it implemented on the Pocket-Version ? We want to show the importent lines in another linewidth, but it doesn't work!


You should use LinePen.Width as done in your example project but this doesn't work. It is a bug and I've added it to our defect list (TF02011400) to be fixed for future releases.

Posted: Fri May 12, 2006 7:43 am
by 9640546
Hi Narcís,
You should use LinePen.Width as done in your example project
Yes, that's what i mean ;)
Have you tested the example project you posted in a non-Beckhoff Windows CE device?
Yes, now i have tested it on an LXE Barcode-Scanner with the same OS (Windows CE 5.0 Build 1400) and the Bug is also present on this device.

ciao Thomas

Posted: Fri Jun 16, 2006 4:41 pm
by 9787414
This may be related to another post "OutOfMemoryException CustomLabels"

Posted: Mon Jul 17, 2006 12:01 pm
by 9640546
Hi,

i have now istalled the DebugBuild from 9. June (v2.0.50727). Now it seems that the memory bug is fixed!
But the 'LinePen.Width' remained not working.


ciao Thomas

Posted: Mon Jul 17, 2006 12:09 pm
by narcis
Hi Thomas,

Excellent! Thanks for the information.

Regarding the LinePen.Width issue is not still fixed.

Posted: Wed Mar 07, 2007 10:56 am
by 9640546
Hi,
You should use LinePen.Width as done in your example project but this doesn't work. It is a bug and I've added it to our defect list (TF02011400) to be fixed for future releases.
When will this Bug be fixed :roll:

ciao Thomas

Posted: Wed Mar 07, 2007 1:47 pm
by narcis
Hi Thomas,

I've checked that the issue hasn't been fixed yet. I can't give you a date for a fix. Please be aware at this forum for new release announcements and what's being implemented on them.