English 中文(简体)
C# 积极建立和实行控制
原标题:Dynamically creating and freeing controls in C#

是一个新事物。 土地网和来自德尔菲的背景,我习惯于在需要时以人工方式建立控制。

在网内,收集了垃圾,我猜测你不需要明确解除控制。

在我的案件(WinForms)中,我充满活力地把一个包含一些其他控制的花板的流放。 在某些情况下,我需要删除一些小组。 我为实现这一目标做了哪些工作。

flowPanel.Controls.Remove(thePanelToRemove);

这产生了必要的效果:小组从花名册上消失,但我看不到的是:垃圾收集者是否删除控制? 这将是理想的行为,因为我会创造许多控制手段,在用户删除时,更不用使用。 如果不是的话,我如何能够确保取消控制? 缩略语

flowPanel.Controls.Remove(thePanelToRemove);
thePanelToRemove.Free();

或类似?

最佳回答

答案:是,当需要记忆时,停车场收集器将取消控制。

更长的答复: 一些控制要求垃圾收集器释放资源。 这些控制实施可识别的接口,如果你不再需要,你应要求处置控制。 处置将清理这些未管理的资源。

问题回答

This have the needed effect: the panel disappears from the flowLayoutPanel, but what I don t get is: does the garbage collector deletes the control?

是的,如果物体不属于范围,则有资格获得垃圾收集。 不要说什么。 免费方法。

假定控制没有其他东西提及,则在移除时,其参考数字将降至零,并将按预期收集垃圾。 这是简明的描述(如果你想读更多的话,以下链接),但作为全面管理<><>>资源的一般规则,你很少需要担心决定性的处置和最后定稿。

当然,控制下提及的任何未管理<>资源都应予以释放和/或妥善处置。 未经管理的资源可以是档案流、数据库连接、参考用于图像处理、从Win32APIC获得的窗口操作的未经管理的星座阵列等。

Overview of garbage Collection in .Net http://geekswithblogs.net/sdorman/archive/2008/11/07/clr-4.0-garbage- Collection-changes.aspx“rel=”nofollow。 c# 4.0。

garbage Collection





相关问题
Bring window to foreground after Mutex fails

I was wondering if someone can tell me what would be the best way to bring my application to the foreground if a mutex was not able to be created for a new instance. E.g.: Application X is running ...

How to start WinForm app minimized to tray?

I ve successfully created an app that minimizes to the tray using a NotifyIcon. When the form is manually closed it is successfully hidden from the desktop, taskbar, and alt-tab. The problem occurs ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

Handle DataTable.DataRow cell change event

I have a DataTable that has several DataColumns and DataRow. Now i would like to handle an event when cell of this DataRow is changed. How to do this in c#?

Apparent Memory Leak in DataGridView

How do you force a DataGridView to release its reference to a bound DataSet? We have a rather large dataset being displayed in a DataGridView and noticed that resources were not being freed after the ...

ALT Key Shortcuts Hidden

I am using VS2008 and creating forms. By default, the underscore of the character in a textbox when using an ampersand is not shown when I run the application. ex. "&Goto Here" is not ...

WPF-XAML window in Winforms Application

I have a Winforms application coded in VS C# 2008 and want to insert a WPF window into the window pane of Winforms application. Could you explain me how this is done.

热门标签