dataGridView1  绑定了数据  BindingList<T> 类型的,其他线程会改变这个BindingList<T>;T类型:
   public class TaskData : INotifyPropertyChanged
    {
public event PropertyChangedEventHandler PropertyChanged;
        private int _编号;
        public int 编号
        {
            get { return _编号; }
            set
            {
                if (_编号 != value)
                {
                    _编号 = value;
                    try
                    {
                        PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("编号"));
                    }
                    catch (Exception err)
                    {
                 
                    }
                }
            }
        }
下面很多字段类型
......}winform 应用程序 ,过一会就开始内存不断增长,几百M,两天下来占用1G多,但我找了几个月了都找不到原因,和解决办法。
下面是 .net memory profiler  给出的, 说是实例无法被销毁。Instances queued for finalization (excessive finalization, finalizer stuck, or resurrected instances) (Show details) (Ignore...)
This type has 10,000 instances that are queued for finalization. This can indicate that a Finalizer method is stuck, which will prevent instances from being finalized and cause memory leaks.#13,518*, #13,517*, #13,521*, #13,519*, #13,516*, #13,512*, #13,510*, #13,514*, #13,513*, #13,523*, (...)下面是调用堆栈。
System.Windows.Forms.Internal.WindowsFont.FromHfont( IntPtr,bool )
System.Windows.Forms.Internal.WindowsFont.FromHfont( IntPtr )
System.Windows.Forms.Internal.WindowsFont.FromHdc( IntPtr )
System.Windows.Forms.Internal.DeviceContext.get_Font()
System.Windows.Forms.Internal.DeviceContext.SelectFont( WindowsFont )
System.Windows.Forms.Internal.WindowsGraphics.DrawText( string,WindowsFont,Rectangle,Color,Color,IntTextFormatFlags )
System.Windows.Forms.Internal.WindowsGraphics.DrawText( string,WindowsFont,Rectangle,Color,IntTextFormatFlags )
System.Windows.Forms.TextRenderer.DrawText( IDeviceContext,string,Font,Rectangle,Color,TextFormatFlags )
System.Windows.Forms.DataGridViewTextBoxCell.PaintPrivate( Graphics,Rectangle,Rectangle,int,DataGridViewElementStates,object,string,DataGridViewCellStyle,DataGridViewAdvancedBorderStyle,DataGridViewPaintParts,bool,bool,bool )
System.Windows.Forms.DataGridViewTextBoxCell.Paint( Graphics,Rectangle,Rectangle,int,DataGridViewElementStates,object,object,string,DataGridViewCellStyle,DataGridViewAdvancedBorderStyle,DataGridViewPaintParts )
System.Windows.Forms.DataGridViewCell.PaintWork( Graphics,Rectangle,Rectangle,int,DataGridViewElementStates,DataGridViewCellStyle,DataGridViewAdvancedBorderStyle,DataGridViewPaintParts )
System.Windows.Forms.DataGridViewRow.PaintCells( Graphics,Rectangle,Rectangle,int,DataGridViewElementStates,bool,bool,DataGridViewPaintParts )
System.Windows.Forms.DataGridViewRow.Paint( Graphics,Rectangle,Rectangle,int,DataGridViewElementStates,bool,bool )
System.Windows.Forms.DataGridView.PaintRows( Graphics,Rectangle,Rectangle,bool )
System.Windows.Forms.DataGridView.PaintGrid( Graphics,Rectangle,Rectangle,bool,bool )
System.Windows.Forms.DataGridView.OnPaint( PaintEventArgs )
System.Windows.Forms.Control.PaintWithErrorHandling( PaintEventArgs,short )
System.Windows.Forms.Control.WmPaint( ref Message )
System.Windows.Forms.Control.WndProc( ref Message )
System.Windows.Forms.DataGridView.WndProc( ref Message )
System.Windows.Forms.Control.ControlNativeWindow.OnMessage( ref Message )
System.Windows.Forms.Control.ControlNativeWindow.WndProc( ref Message )
System.Windows.Forms.NativeWindow.Callback( IntPtr,int,IntPtr,IntPtr )
[Native to managed transition]
[Managed to native transition]
[Truncated]

解决方案 »

  1.   

    额,我们可不知道你到底干了啥,你要是加了100w条记录呢?你从不清list,gc当然不释放,gc只释放你不用的,你说我100w条记录都用,自然微软也不干帮你释放
      

  2.   

    正常情况下,默认监听list,只显示最近1小时的。如果需要查询以前的则是另外的查询UI去数据持久层找别说dataGridView1,你就是一个execel你不停的写他也扛不住