Page 1 of 1

Memory Leak Custom3DGrid

Posted: Wed Sep 30, 2020 8:26 am
by 15689012
Hello,

we have a Memory Leak in Custom3DGrid.
Each access will let the memory grow.
Is there a knwon issue with Custom3DGrid?

System:
TeeChart Version 4.2020.5.25
IDE: VS2019
Language: C#
Windows 10 Pro 1909

Re: Memory Leak Custom3DGrid

Posted: Thu Oct 01, 2020 7:04 am
by Christopher
Hello,

Despite being a public class, Custom3DGrid was not designed to be instantiated - it was designed as a base class, and as such is the base class of the classes ColorGrid, Contour, Surface, and Tower. Which of these four series types are you using? Could you please send us a Short, Self Contained, Correct (Compilable), Example (defined here) with which we can reproduce your issue?

Re: Memory Leak Custom3DGrid

Posted: Thu Oct 01, 2020 7:46 am
by 15689012
Here you will find a sample project: https://hcckpm-my.sharepoint.com/:u:/g/ ... w?e=3Y6gGB

After each click the memory usage will grow. It will fall down after a few clicks but not to the starting point.
In the sample we use the ColorGrid.
We also tested the same behavior on a second system. That's the reason why it is not registered.
We also used the latest nuget downloadable version from September.
Start.jpg
Start.jpg (174.37 KiB) Viewed 11072 times
after_10_clicks.jpg
after_10_clicks.jpg (175.75 KiB) Viewed 11072 times

Re: Memory Leak Custom3DGrid

Posted: Thu Oct 01, 2020 10:59 am
by Christopher
Hello,

I've modified slightly your project to use a timer (which fires twice a second) instead of manually using a mouse:

Code: Select all

    /// <summary>
    /// Interaktionslogik für MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        private Steema.TeeChart.WPF.Styles.ColorGrid seriesCG;
        private int clicks = 0;
        private DispatcherTimer _timer;


        public MainWindow()
        {
            InitializeComponent();

            _timer = new DispatcherTimer();
            _timer.Interval = new TimeSpan(0, 0, 0, 0, 500);
            _timer.Tick += _timer_Tick;
            InitChart();

            _timer.IsEnabled = true;
        }

        private void _timer_Tick(object sender, EventArgs e)
        {
            clicks++;
            NewData();
        }

        private void InitChart()
        {
            Chart1.Legend.LegendStyle = Steema.TeeChart.WPF.LegendStyles.Values;
            Chart1.Legend.Alignment = LegendAlignments.Bottom;

            Chart1.Aspect.View3D = false;

            seriesCG = new Steema.TeeChart.WPF.Styles.ColorGrid(Chart1.Chart);
            seriesCG.PaletteStyle = Steema.TeeChart.WPF.Styles.PaletteStyles.Rainbow;
            seriesCG.UseColorRange = false;
            seriesCG.UsePalette = true;

            seriesCG.Pen.Visible = false;

            NewData();
        }

        private void NewData()
        {
            int arraySizeX = 512;
            int arraySizeY = 360;
            int arraySize = arraySizeX * arraySizeY;

            short[] dataX = new short[arraySize];
            short[] dataZ = new short[arraySize];
            float[] dataY = new float[arraySize];

            int index = 0;
            int inv = 1;
            if ((clicks % 2) == 0) inv = -1;

            for (int x = 0; x < arraySizeX; x++)
            {
                for (int y = 0; y < arraySizeY; y++)
                {
                    dataX[index] = Convert.ToInt16(x);
                    dataZ[index] = Convert.ToInt16(y);
                    dataY[index] = index * inv / 1000;
                    index++;
                }
            }
            seriesCG.Clear();
            seriesCG.Add(dataX, dataY, dataZ);
            Chart1.Header.Text = clicks.ToString();
        }

        private void Chart1_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            clicks++;
            NewData();
        }
    }
I then ran this code in a Memory Usage diagnostic session as detailed here using the latest publicly available version of Visual Studio 2019. I've uploaded the results here in the form of a *.diagsession file which you can open in Visual Studio 2019. The results look like this:
devenv_2020-10-01_12-07-57.png
devenv_2020-10-01_12-07-57.png (79.51 KiB) Viewed 11060 times
As you can see, this specific diagnostic session has failed to detect any kind of memory leak in the code.