Memory leak after winform closes using custom table

I have a C # WinForm dialog box that contains a custom table control with rows and cells, which are also custom controls. After closing (without hiding) this dialog, I have a memory leak (and this is confirmed by the .NET memory profiler).

From the information I get from the profiler, I think he is dealing with the removal of these controls, but I'm not sure how to fix it.

In a table control, I have a list of rows:

private readonly List<CustomRow> _rows = new List<CustomRow>(); 

In each row, I have a list of cells:

List<CustomCell> _cells = new List<CustomCell>();

To date, disposal in the controls has been done using automatic code in the designer.cs file:

protected override void Dispose(bool disposing)
{
    if (disposing && (components != null))
    {
         components.Dispose();
    }
    base.Dispose(disposing);
}

, .cs - , , :

protected override void Dispose(bool disposing)
{
     if (disposing)
     {
          if (components != null)
          {
              components.Dispose();
          }
          // dispose each row here                
     }
     base.Dispose(disposing);
}

, ? ( ?)

+4
1

Dispose , . Dispose .

. /​​libaries, ( ) Dispose.


, , , , , . , datarow/table (, RowChanged), , (- ) . , , .

, , , , .

: / reset GridView1.DataSource = Null. / DataTable

, , "" ,

+3

Source: https://habr.com/ru/post/1621780/


All Articles