改变颜色会导致内存泄漏

时间:2016-11-22 20:23:32

标签: c# .net memory-leaks colors

我正在写一个非常有用的程序。此功能可更改表单某些项目的颜色。一旦启动,程序的内存就会在任务管理器中增加。我怎么能解决这个问题?

private void Autism_Tick(object sender, EventArgs e)
            {
                this.BackColor = Color.FromArgb(rng.Next(1, 256), rng.Next(1, 256), rng.Next(1, 256));
                dgv_fak.BackgroundColor = Color.FromArgb(rng.Next(1, 256), rng.Next(1, 256), rng.Next(1, 256));
                RTB_info.BackColor = Color.FromArgb(rng.Next(1, 256), rng.Next(1, 256), rng.Next(1, 256));
                menuStrip1.BackColor = Color.FromArgb(rng.Next(1, 256), rng.Next(1, 256), rng.Next(1, 256));
                textBox1.BackColor = Color.FromArgb(rng.Next(1, 256), rng.Next(1, 256), rng.Next(1, 256));

                for (int i = 0; i < dgv_fak.RowCount; i++)
                {
                    for (int j = 0; j < dgv_fak.ColumnCount; j++)
                    {
                        dgv_fak.Rows[i].Cells[j].Style.BackColor = Color.FromArgb(rng.Next(1, 256), rng.Next(1, 256), rng.Next(1, 256));
                    }
                }
                dgv_fak.ColumnHeadersDefaultCellStyle.BackColor = Color.FromArgb(rng.Next(1, 256), rng.Next(1, 256), rng.Next(1, 256));
            }

0 个答案:

没有答案