Menu

Possible memory leak

2016-12-21
2016-12-21
  • kristian mo

    kristian mo - 2016-12-21

    Hey there migth be a a memory leak with the ExpandingIcon.IconChanged static event. The TreeViewAdv is used many places in our application and using SciTech .NET Memory Profiler I get EventHandler roots that are not removed.

    I tried to reproduce it with a smaller application:

    Steps:
    1. Create a new project MemoryLeak as an Windows Forms Application in Visual Studio 201X
    2. Include a reference to Aga.Controls.dll 1.7.0.0
    3. Create a new form TreeViewAdv, drag and drop a TreeViewAdv onto it from the toolbox.
    4. In the automatically created Form1 add a button, and a button click event.
    5. Launch the TreeViewAdv from the button function

    Form1.cs:

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows.Forms;
    
    namespace MemoryLeak
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
    
            private void button1_Click(object sender, EventArgs e)
            {
                var form = new TreeViewAdv();
                form.ShowDialog();
            }
        }
    }
    

    TreeViewAdv.cs:

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows.Forms;
    
    namespace MemoryLeak
    {
        public partial class TreeViewAdv : Form
        {
            public TreeViewAdv()
            {
                InitializeComponent();
            }
        }
    }
    

    TreeViewAdv.Designer.cs:

    namespace MemoryLeak
    {
        partial class TreeViewAdv
        {
            /// <summary>
            /// Required designer variable.
            /// </summary>
            private System.ComponentModel.IContainer components = null;
    
            /// <summary>
            /// Clean up any resources being used.
            /// </summary>
            /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
            protected override void Dispose(bool disposing)
            {
                if (disposing && (components != null))
                {
                    components.Dispose();
                }
                base.Dispose(disposing);
            }
    
            #region Windows Form Designer generated code
    
            /// <summary>
            /// Required method for Designer support - do not modify
            /// the contents of this method with the code editor.
            /// </summary>
            private void InitializeComponent()
            {
                this.treeViewAdv1 = new Aga.Controls.Tree.TreeViewAdv();
                this.SuspendLayout();
                // 
                // treeViewAdv1
                // 
                this.treeViewAdv1.BackColor = System.Drawing.SystemColors.Window;
                this.treeViewAdv1.DefaultToolTipProvider = null;
                this.treeViewAdv1.Dock = System.Windows.Forms.DockStyle.Fill;
                this.treeViewAdv1.DragDropMarkColor = System.Drawing.Color.Black;
                this.treeViewAdv1.LineColor = System.Drawing.SystemColors.ControlDark;
                this.treeViewAdv1.Location = new System.Drawing.Point(0, 0);
                this.treeViewAdv1.Model = null;
                this.treeViewAdv1.Name = "treeViewAdv1";
                this.treeViewAdv1.SelectedNode = null;
                this.treeViewAdv1.Size = new System.Drawing.Size(284, 262);
                this.treeViewAdv1.TabIndex = 0;
                this.treeViewAdv1.Text = "treeViewAdv1";
                // 
                // TreeViewAdv
                // 
                this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
                this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
                this.ClientSize = new System.Drawing.Size(284, 262);
                this.Controls.Add(this.treeViewAdv1);
                this.Name = "TreeViewAdv";
                this.Text = "TreeViewAdv";
                this.ResumeLayout(false);
    
            }
    
            #endregion
    
            private Aga.Controls.Tree.TreeViewAdv treeViewAdv1;
        }
    }
    

    When I start the application and open/close TreeViewAdv with the memory profiler I get an event handler that is active for every open/close cycle.

     

    Last edit: kristian mo 2016-12-21
  • kristian mo

    kristian mo - 2016-12-21

    Sorry, seems I failed at googling.
    Fix available here: https://sourceforge.net/p/treeviewadv/bugs/28/

     

Log in to post a comment.