<System.Diagnostics.DebuggerNonUserCode()> _
Protected Overrides Sub Dispose(ByVal disposing As Boolean)
Try
If disposing AndAlso components IsNot Nothing Then
components.Dispose()
End If
Finally
MyBase.Dispose(disposing)
End Try
有人可以告诉我为什么我们在designer.vb
中使用它?
答案 0 :(得分:3)
Dispose
用于释放未由运行时管理的资源(非托管资源)。这包括文件,流,字体等。garbage collector在不再使用该对象时自动释放分配给托管对象的内存。但是,无法预测垃圾收集何时发生。此外,垃圾收集器不了解非托管资源,例如窗口句柄,或打开文件和流。
在您的代码中,基类的Dispose
方法被子类实现覆盖,因此overriden
关键字调用Mybase.Dispose
。基类为IContainer
,子类为Form
。 Dispose
界面中提供了designer.vb
方法。
在Dispose
中,此自动生成的代码用于在表单上调用Dispose
时调用表单组件上的<System.Diagnostics.DebuggerNonUserCode()> _
Protected Overrides Sub Dispose(ByVal disposing As Boolean)
Try
' If Dispose() has been called explicitly free both managed and
' unmanaged resources (disposing = true)
' and there are components in the form
If disposing AndAlso components IsNot Nothing Then
' Free the resources used by components
components.Dispose()
End If
Finally
' Once done disposing the current form's resources,
' dispose the resources held by its base class
' Finally clause executes this code block (to dispose base class)
' whether or not an exception has been encountered while
' disposing the resources in the form
MyBase.Dispose(disposing)
End Try
,即表单处理时,也要处理它的组件。
{{1}}
更多信息