Memory Leak in TeeChart Pocket OnPaint !
Posted: Thu Mar 16, 2006 8:30 am
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]
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 );
}
}
}