Windows.Forms应用程序中超过4297000000个GDI对象! ListView的泄漏。 [英] over 4297000000 of GDI objects in a Windows.Forms application! ListView's leak.

查看:69
本文介绍了Windows.Forms应用程序中超过4297000000个GDI对象! ListView的泄漏。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

今天我们发现了一个关于ListView的关键问题来自

Windows.Forms。在几台使用Win2K和XP的机器上确认了它。


这里的问题是:创建一个大约50000行的ListView。现在使用任务

manager来查看进程的GDI用法。一切看起来都很正常。


现在抓住ListView的滚动条并开始向下移动它。你有
来保持恒定速度,以便不断重新绘制ListView。

查看应用程序的GDI用法。它开始增加,从

21开始,一直到1000-5000。如果你得到ListView的底部,

立即开始向上滚动,以便ListView不断重新刷新
。你会看到GDI对象计数达到10000然后

跳到超过4297000000!记得保持滚动速度!

从IDE运行的
甚至可以使Windows GDI子系统完全破坏并挂起整个系统(这就是我们的应用程序在它被滥用的时候会这样做!)。


这里是简单的代码。编译它,按下按钮按钮1。并观看

GDI的使用情况。

附件中的
我已经包含了任务管理器的快照,显示了

GDI用法。我真的很想听到任何人的消息。可以

有人确认问题或指出我的错误吗?


问候,

Wiktor

- -------------------------------------------------- -

使用System;

使用System.Drawing;

使用System.Collections;

使用System。 ComponentModel;

使用System.Windows.Forms;

使用System.Data;


命名空间vicTestF

{

公共类Form1:System.Windows.Forms.Form

{

private System.Windows.Forms.ListView listView1;

private System.Windows.Forms.ColumnHeader columnHeader1;

private System.Windows.Forms.ColumnHeader columnHeader2;

private System.Windows.Forms。 ColumnHeader columnHeader3;

private System.Windows.Forms.Button button1;

private System.ComponentModel.Container components = null;


public Form1()

{

InitializeComponent();

}


protected override void Dispose(bool disposing)

{

if(disposing)

{

if(components!) = null)

{

components.Dispose();

}

}

base.Dispose(disposing);

}


#region Windows窗体设计器生成的代码

private void InitializeComponent()

{

this.listView1 = new System.Windows.Forms.ListView();

this.columnHeader1 = new System.Windows.Forms .ColumnHeader();

this.columnHeader2 = new System.Windows.Forms.ColumnHeader();

this.columnHeader3 = new System.Windows.Forms.ColumnHeader() ;

this.button1 = new System.Windows.Forms.Button();

this.SuspendLayout();

//

// listView1

//

this.listView1.Columns.AddRange(new System.Windows.Forms.ColumnHeader [] {

this.columnHeader1,

this.columnHeader2,

this.columnHeader3});

this.listView1.Dock = System.Windows.Forms.DockStyle.Fill;

this.listView1.GridLines = true;

this.listView1.Location = new System.Drawing.Point(0,32);

this.listView1.Name =" listView1";

this.listView1.Size = new System.Drawing。大小(496,289);

this.listView1.TabIndex = 0;

this.listView1.View = System.Windows.Forms.View.Details;

//

// columnHeader1

//

this.columnHeader1.Width = 143;

//

// columnHeader2

//

this.columnHeader2.Width = 115;

/ /

// columnHeader3

//

this.columnHeader3.Width = 229;

//

// button1

//

this.button1.Dock = System.Windows.Forms.DockStyle.Top;

this.button1.Name =" button1";

this.button1.Size = new System.Drawing.Size(496,32);

this.button1。 TabIndex = 1;

this.butto n1.Text =" button1";

this.button1.Click + = new System.EventHandler(this.button1_Click);

//

// Form1

//

this.AutoScaleBaseSize = new System.Drawing.Size(5,13);

this.ClientSize = new System.Drawing.Size(496,321);

this.Controls.AddRange(new System.Windows.Forms.Control [] {

this.listView1,

this.button1});

this.Name =" Form1";

this.Text =" Form1";

this.ResumeLayout(false);


}

#endregion


[STAThread ]

static void Main()

{

Application.Run(new Form1());

}


private void button1_Click(object sender,System.EventArgs e)

{

listView1.BeginUpdate();


ListViewItem li;

for(int i = 0; I< 50000; i ++)

{

// ListViewItem li = listView1.Items.Add(" item" + i.ToString());

li = listView1.Items.Add(" item" + i.ToString());

li.SubItems.Add(" qwer");

li。 SubItems.Add(" qwer");

}


MessageBox.Show(" before endupdate");

listView1.EndUpdate();

}

}

}



解决方案

好吧我不知道到底发生了什么,虽然你应该

下载一个分析器,看看你的程序正在使用什么。

无论哪种方式,50,000行甚至超过你应该考虑将

放入ListView!没有用户可以接受所有这些!


HTH

Kieran


" ; Wiktor Zychla <即**** @ microsoft.com.no.spam>写在消息

新闻:%2 ***************** @ TK2MSFTNGP09.phx.gbl ...

今天我们已经从Windows.Forms中发现了关于ListView的一个关键问题。在几台使用Win2K和XP的机器上确认了它。

这里的问题是:创建一个大约50000行的ListView。现在使用任务
管理器来查看进程的GDI用法。一切似乎都很正常。

现在抓住ListView的滚动条并开始向下移动它。你有保持恒定的速度,以便不断重新绘制ListView。
查看应用程序的GDI用法。它开始增加,在21点开始
并且通过1000-5000。如果你得到ListView的底部,
立即开始向上滚动,以便ListView不断重新绘制。你会看到GDI对象计数达到10000和
然后跳到超过4297000000!记得保持滚动速度!从IDE运行甚至可以使Windows GDI子系统完全破坏并挂起整个系统(这是我们的应用程序在
时所做的事情被误用了!)。

这里是简单的代码。编译它,按下按钮按钮1。并且观察GDI的使用情况。

在附件中我已经包含了任务管理器的快照,显示了
GDI的使用情况。我真的很想听到任何人的消息。可以
任何人确认问题或指出我的错误吗?

问候,
Wiktor
----------------- ------------------------------------
使用System;
使用System。绘图;
使用System.Collections;
使用System.ComponentModel;
使用System.Windows.Forms;
使用System.Data;

命名空间vicTestF
{公共类Form1:System.Windows.Forms.Form
私有System.Windows.Forms.ListView listView1;
私有System.Windows.Forms。 ColumnHeader columnHeader1;
private System.Windows.Forms.ColumnHeader columnHeader2;
private System.Windows.Forms.ColumnHeader columnHeader3;
private System.Windows.Forms.Button button1;
private System.ComponentModel.Container components = null;

public Form1()
{
InitializeComponent();
}

受保护的覆盖无效处置(布尔处理)
{
如果(处置)
{
if(components!= null)
{
components.Dispose();
}
}
base.Dispose(disposing);
}

#region Windows窗体设计器生成的代码
private void InitializeComponent()
{
this.listView1 = new System.Windows.Forms.ListView();
this.columnHeader1 = new System.Windows.Forms.ColumnHeader();
this.columnHeader2 = new System.Windows.Forms.ColumnHeader();
this.columnHeader3 = new System.Windows.Forms.ColumnHeader ();
this.button1 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// listView1
/ /
this.listView1.Columns.AddRange(new System.Windows.Forms.ColumnHeader []
{this.columnHeader1,
this.columnHeader2,
this.columnHeader3});
this.listView1.Dock = System.Windows.Forms.DockStyle.Fill;
this.listView1.GridLines = tru e;
this.listView1.Location = new System.Drawing.Point(0,32);
this.listView1.Name =" listView1";
this.listView1.Size = new System.Drawing.Size(496,289);
this.listView1.TabIndex = 0;
this.listView1.View = System.Windows.Forms.View.Details;
//
// columnHeader1
//
this.columnHeader1.Width = 143;
//
// columnHeader2
//
this.columnHeader2 .Width = 115;
// columnHeader3
//
this.columnHeader3.Width = 229;
//
// button1
//
this.button1.Dock = System.Windows.Forms.DockStyle.Top;
this.button1.Name =" button1";
this.button1.Size = new System.Drawing.Size(496,32);
this.button1.TabIndex = 1;
this.button1.Text =" button1";
this.button1.Click + = new System.EventHandler(this.button1_Click);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5,13);
this.ClientSize = new System.Drawing.Size(496,321);
this.Controls.AddRange(new System.Windows .Forms.Control [] {
this.listView1,
this.button1});
this.Name =" Form1";
this.Text =" Form1" ;
this.ResumeLayout(false);

}
#endregion

[STAThread]
static void Main()
{
Application.Run(new Form1());
}
私有void button1_Click(对象发送者,System.EventArgs e)

listView1.BeginUpdate();

ListViewItem li;
for(int i = 0; I< 50000; i ++)
// ListViewItem li = listView1.Items.Add(" item" + i.ToString());
li = listView1.Items.Add(" item" + i.ToString());
li.SubItems.Add(" qwer");
li.SubItems.Add(" qwer");
}
<消息框.Show(" before endupdate");
listView1.EndUpdate();
}
}
}



>无论哪种方式,50,000行甚至超过您应该考虑将

放入ListView!没有用户能够接受所有这些!




当你有2000件物品甚至1000件时它也会发生。这是一个

合理计数。 50000只是一个例子!


只是尝试一下,如果可以的话,帮我解释一下。问题不会发生,例如,如果你在旧的VB中做同样的事情,那么你会做同样的事情。因此它是一个Windows.Forms问题。


您可能运行调试版本,可以在发布模式下检查这个。


Willy。


" Wiktor Zychla" <即**** @ microsoft.com.no.spam>在消息新闻中写道:%2 ***************** @ TK2MSFTNGP09.phx.gbl ...

今天我们发现了一个关键问题关于来自Windows.Forms的ListView。在几台使用Win2K和XP的机器上确认了它。

这里的问题是:创建一个大约50000行的ListView。现在使用任务
管理器来查看进程的GDI用法。一切似乎都很正常。

现在抓住ListView的滚动条并开始向下移动它。你有保持恒定的速度,以便不断重新绘制ListView。
查看应用程序的GDI用法。它开始增加,从
21开始并经历1000-5000。如果你得到ListView的底部,
立即开始向上滚动,以便ListView不断重新绘制。你会看到GDI对象计数达到10000然后
跳到超过4297000000!记得保持滚动速度!从IDE运行甚至可以使Windows GDI子系统完全破坏并挂起整个系统(这就是我们的应用程序在做什么时
被误用了!)。

这里是简单的代码。编译它,按下按钮按钮1。并观察GDI的使用情况。

在附件中我已经包含了任务管理器的快照,显示了GDI的使用情况。我真的很想听到任何人的消息。可以
任何人确认问题或指出我的错误吗?

问候,
Wiktor
----------------- ------------------------------------
使用System;
使用System。绘图;
使用System.Collections;
使用System.ComponentModel;
使用System.Windows.Forms;
使用System.Data;

命名空间vicTestF
{公共类Form1:System.Windows.Forms.Form
私有System.Windows.Forms.ListView listView1;
私有System.Windows.Forms。 ColumnHeader columnHeader1;
private System.Windows.Forms.ColumnHeader columnHeader2;
private System.Windows.Forms.ColumnHeader columnHeader3;
private System.Windows.Forms.Button button1;
private System.ComponentModel.Container components = null;

public Form1()
{
InitializeComponent();
}

受保护的覆盖无效处置(布尔处理)
{
如果(处置)
{
if(components!= null)
{
components.Dispose();
}
}
base.Dispose(disposing);
}

#region Windows窗体设计器生成的代码
private void InitializeComponent()
{
this.listView1 = new System.Windows.Forms.ListView();
this.columnHeader1 = new System.Windows.Forms.ColumnHeader();
this.columnHeader2 = new System.Windows.Forms.ColumnHeader();
this.columnHeader3 = new System.Windows.Forms.ColumnHeader ();
this.button1 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// listView1
/ /
this.listView1.Columns.AddRange(new System.Windows.Forms.ColumnHeader [] {
this.columnHeader1,
this.columnHeader2,
this.columnHeader3});
this.listView1.Dock = System.Windows.Forms.DockStyle.Fill;
this.listView1.GridLines = tr ue;
this.listView1.Location = new System.Drawing.Point(0,32);
this.listView1.Name =" listView1";
this.listView1.Size = new System.Drawing.Size(496,289);
this.listView1.TabIndex = 0;
this.listView1.View = System.Windows.Forms.View.Details;
//
// columnHeader1
//
this.columnHeader1.Width = 143;
//
// columnHeader2
//
this.columnHeader2 .Width = 115;
// columnHeader3
//
this.columnHeader3.Width = 229;
//
// button1
//
this.button1.Dock = System.Windows.Forms.DockStyle.Top;
this.button1.Name =" button1";
this.button1.Size = new System.Drawing.Size(496,32);
this.button1.TabIndex = 1;
this.button1.Text =" button1";
this.button1.Click + = new System.EventHandler(this.button1_Click);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5,13);
this.ClientSize = new System.Drawing.Size(496,321);
this.Controls.AddRange(new System.Windows .Forms.Control [] {
this.listView1,
this.button1});
this.Name =" Form1";
this.Text =" Form1" ;
this.ResumeLayout(false);

}
#endregion

[STAThread]
static void Main()
{
Application.Run(new Form1());
}
私有void button1_Click(对象发送者,System.EventArgs e)

listView1.BeginUpdate();

ListViewItem li;
for(int i = 0; I< 50000; i ++)
// ListViewItem li = listView1.Items.Add(" item" + i.ToString());
li = listView1.Items.Add(" item" + i.ToString());
li.SubItems.Add(" qwer");
li.SubItems.Add(" qwer");
}
<消息框.Show(" before endupdate");
listView1.EndUpdate();
}
}
}



today we''ve found a critical issue regarding the ListView from
Windows.Forms. it was confirmed on several machines with Win2K and XP.

here''s the problem: create a ListView with about 50000 rows. now use task
manager to see the GDI usage of the process. everything seems normal.

now catch the ListView''s scroller and start to move it downwards. you have
to hold the constant speed so that the ListView is constantly repainted.
look at the GDI usage of the application. it starts to increase, starting at
21 and going through 1000-5000. if you get the bottom of the ListView,
immediately start to scroll it upwards so that the ListView is constantly
repainted. you''ll see that the GDI objects count reaches the 10000 and then
jumps to over 4297000000! remember to keep the scrolling speed!

running from the IDE can even make the Windows GDI subsystem completely
broken and hang the whole system (this is what our application does when it
is misused!).

here''s the simple code. compile it, press the button "button 1" and watch
the GDI usage.

in the attachment I''ve included the snapshot of the Task Manager showing the
GDI usage. I am really desperate to hear from anyone about that. could
anyone confirm the problem or point my mistake?

Regards,
Wiktor
-----------------------------------------------------
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace vicTestF
{
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.ListView listView1;
private System.Windows.Forms.ColumnHeader columnHeader1;
private System.Windows.Forms.ColumnHeader columnHeader2;
private System.Windows.Forms.ColumnHeader columnHeader3;
private System.Windows.Forms.Button button1;
private System.ComponentModel.Container components = null;

public Form1()
{
InitializeComponent();
}

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

#region Windows Form Designer generated code
private void InitializeComponent()
{
this.listView1 = new System.Windows.Forms.ListView();
this.columnHeader1 = new System.Windows.Forms.ColumnHeader();
this.columnHeader2 = new System.Windows.Forms.ColumnHeader();
this.columnHeader3 = new System.Windows.Forms.ColumnHeader();
this.button1 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// listView1
//
this.listView1.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
this.columnHeader1,
this.columnHeader2,
this.columnHeader3});
this.listView1.Dock = System.Windows.Forms.DockStyle.Fill;
this.listView1.GridLines = true;
this.listView1.Location = new System.Drawing.Point(0, 32);
this.listView1.Name = "listView1";
this.listView1.Size = new System.Drawing.Size(496, 289);
this.listView1.TabIndex = 0;
this.listView1.View = System.Windows.Forms.View.Details;
//
// columnHeader1
//
this.columnHeader1.Width = 143;
//
// columnHeader2
//
this.columnHeader2.Width = 115;
//
// columnHeader3
//
this.columnHeader3.Width = 229;
//
// button1
//
this.button1.Dock = System.Windows.Forms.DockStyle.Top;
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(496, 32);
this.button1.TabIndex = 1;
this.button1.Text = "button1";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(496, 321);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.listView1,
this.button1});
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);

}
#endregion

[STAThread]
static void Main()
{
Application.Run(new Form1());
}

private void button1_Click(object sender, System.EventArgs e)
{
listView1.BeginUpdate();

ListViewItem li;
for ( int i=0; i<50000; i++ )
{
// ListViewItem li = listView1.Items.Add( "item" + i.ToString() );
li = listView1.Items.Add( "item" + i.ToString() );
li.SubItems.Add( "qwer" );
li.SubItems.Add( "qwer" );
}

MessageBox.Show( "before endupdate" );
listView1.EndUpdate();
}
}
}



解决方案

Well I dont know exactly whats going on here although you should probably
download a profiler and see exactly what is being used by your program.
Either way, 50,000 rows if far more than you should ever consider putting
into a ListView! No user is ever going to be able to take in all of these!

HTH
Kieran

"Wiktor Zychla" <ie****@microsoft.com.no.spam> wrote in message
news:%2*****************@TK2MSFTNGP09.phx.gbl...

today we''ve found a critical issue regarding the ListView from
Windows.Forms. it was confirmed on several machines with Win2K and XP.

here''s the problem: create a ListView with about 50000 rows. now use task
manager to see the GDI usage of the process. everything seems normal.

now catch the ListView''s scroller and start to move it downwards. you have
to hold the constant speed so that the ListView is constantly repainted.
look at the GDI usage of the application. it starts to increase, starting at 21 and going through 1000-5000. if you get the bottom of the ListView,
immediately start to scroll it upwards so that the ListView is constantly
repainted. you''ll see that the GDI objects count reaches the 10000 and then jumps to over 4297000000! remember to keep the scrolling speed!

running from the IDE can even make the Windows GDI subsystem completely
broken and hang the whole system (this is what our application does when it is misused!).

here''s the simple code. compile it, press the button "button 1" and watch
the GDI usage.

in the attachment I''ve included the snapshot of the Task Manager showing the GDI usage. I am really desperate to hear from anyone about that. could
anyone confirm the problem or point my mistake?

Regards,
Wiktor
-----------------------------------------------------
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace vicTestF
{
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.ListView listView1;
private System.Windows.Forms.ColumnHeader columnHeader1;
private System.Windows.Forms.ColumnHeader columnHeader2;
private System.Windows.Forms.ColumnHeader columnHeader3;
private System.Windows.Forms.Button button1;
private System.ComponentModel.Container components = null;

public Form1()
{
InitializeComponent();
}

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

#region Windows Form Designer generated code
private void InitializeComponent()
{
this.listView1 = new System.Windows.Forms.ListView();
this.columnHeader1 = new System.Windows.Forms.ColumnHeader();
this.columnHeader2 = new System.Windows.Forms.ColumnHeader();
this.columnHeader3 = new System.Windows.Forms.ColumnHeader();
this.button1 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// listView1
//
this.listView1.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] { this.columnHeader1,
this.columnHeader2,
this.columnHeader3});
this.listView1.Dock = System.Windows.Forms.DockStyle.Fill;
this.listView1.GridLines = true;
this.listView1.Location = new System.Drawing.Point(0, 32);
this.listView1.Name = "listView1";
this.listView1.Size = new System.Drawing.Size(496, 289);
this.listView1.TabIndex = 0;
this.listView1.View = System.Windows.Forms.View.Details;
//
// columnHeader1
//
this.columnHeader1.Width = 143;
//
// columnHeader2
//
this.columnHeader2.Width = 115;
//
// columnHeader3
//
this.columnHeader3.Width = 229;
//
// button1
//
this.button1.Dock = System.Windows.Forms.DockStyle.Top;
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(496, 32);
this.button1.TabIndex = 1;
this.button1.Text = "button1";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(496, 321);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.listView1,
this.button1});
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);

}
#endregion

[STAThread]
static void Main()
{
Application.Run(new Form1());
}

private void button1_Click(object sender, System.EventArgs e)
{
listView1.BeginUpdate();

ListViewItem li;
for ( int i=0; i<50000; i++ )
{
// ListViewItem li = listView1.Items.Add( "item" + i.ToString() );
li = listView1.Items.Add( "item" + i.ToString() );
li.SubItems.Add( "qwer" );
li.SubItems.Add( "qwer" );
}

MessageBox.Show( "before endupdate" );
listView1.EndUpdate();
}
}
}



> Either way, 50,000 rows if far more than you should ever consider putting

into a ListView! No user is ever going to be able to take in all of these!



it also happens when you have 2000 items or even a 1000. this IS a
reasonable count. 50000 was only an example!

just try it and help me explain it if you can. the problem DOES NOT OCCUR if
you do the same in old VB for example. so it is a Windows.Forms issue.


You probably run the debug version, can you check this in release mode.

Willy.

"Wiktor Zychla" <ie****@microsoft.com.no.spam> wrote in message news:%2*****************@TK2MSFTNGP09.phx.gbl...

today we''ve found a critical issue regarding the ListView from
Windows.Forms. it was confirmed on several machines with Win2K and XP.

here''s the problem: create a ListView with about 50000 rows. now use task
manager to see the GDI usage of the process. everything seems normal.

now catch the ListView''s scroller and start to move it downwards. you have
to hold the constant speed so that the ListView is constantly repainted.
look at the GDI usage of the application. it starts to increase, starting at
21 and going through 1000-5000. if you get the bottom of the ListView,
immediately start to scroll it upwards so that the ListView is constantly
repainted. you''ll see that the GDI objects count reaches the 10000 and then
jumps to over 4297000000! remember to keep the scrolling speed!

running from the IDE can even make the Windows GDI subsystem completely
broken and hang the whole system (this is what our application does when it
is misused!).

here''s the simple code. compile it, press the button "button 1" and watch
the GDI usage.

in the attachment I''ve included the snapshot of the Task Manager showing the
GDI usage. I am really desperate to hear from anyone about that. could
anyone confirm the problem or point my mistake?

Regards,
Wiktor
-----------------------------------------------------
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace vicTestF
{
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.ListView listView1;
private System.Windows.Forms.ColumnHeader columnHeader1;
private System.Windows.Forms.ColumnHeader columnHeader2;
private System.Windows.Forms.ColumnHeader columnHeader3;
private System.Windows.Forms.Button button1;
private System.ComponentModel.Container components = null;

public Form1()
{
InitializeComponent();
}

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

#region Windows Form Designer generated code
private void InitializeComponent()
{
this.listView1 = new System.Windows.Forms.ListView();
this.columnHeader1 = new System.Windows.Forms.ColumnHeader();
this.columnHeader2 = new System.Windows.Forms.ColumnHeader();
this.columnHeader3 = new System.Windows.Forms.ColumnHeader();
this.button1 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// listView1
//
this.listView1.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
this.columnHeader1,
this.columnHeader2,
this.columnHeader3});
this.listView1.Dock = System.Windows.Forms.DockStyle.Fill;
this.listView1.GridLines = true;
this.listView1.Location = new System.Drawing.Point(0, 32);
this.listView1.Name = "listView1";
this.listView1.Size = new System.Drawing.Size(496, 289);
this.listView1.TabIndex = 0;
this.listView1.View = System.Windows.Forms.View.Details;
//
// columnHeader1
//
this.columnHeader1.Width = 143;
//
// columnHeader2
//
this.columnHeader2.Width = 115;
//
// columnHeader3
//
this.columnHeader3.Width = 229;
//
// button1
//
this.button1.Dock = System.Windows.Forms.DockStyle.Top;
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(496, 32);
this.button1.TabIndex = 1;
this.button1.Text = "button1";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(496, 321);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.listView1,
this.button1});
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);

}
#endregion

[STAThread]
static void Main()
{
Application.Run(new Form1());
}

private void button1_Click(object sender, System.EventArgs e)
{
listView1.BeginUpdate();

ListViewItem li;
for ( int i=0; i<50000; i++ )
{
// ListViewItem li = listView1.Items.Add( "item" + i.ToString() );
li = listView1.Items.Add( "item" + i.ToString() );
li.SubItems.Add( "qwer" );
li.SubItems.Add( "qwer" );
}

MessageBox.Show( "before endupdate" );
listView1.EndUpdate();
}
}
}



这篇关于Windows.Forms应用程序中超过4297000000个GDI对象! ListView的泄漏。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆